Question : Powershell saveas xls directory

I am new to PS and have a few scripts I have put together.  I am running them sequentially from a batch file and all of the scripts use directory paths relative to the batch file.  But, when I have data output to an xls file and attempt to saveas it goes directly into the my documents folder for that user.

I would like it to go into a folder relative to the batch file location.

c:
   powershell
        scripts folder
        log folder
        xls folder
        results folder
        batch file

the powershell script in the script folder will call on log files in the log folder using relative paths but when it comes to saving the xls it does not.  Am I missing something here?

thanks,
C


       
1:
2:
3:
4:
5:
6:
7:
8:
9:
$a = New-Object -comobject Excel.Application 
$a.visible = $True
$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)

$d = $c.UsedRange
$d.EntireColumn.AutoFit()
$b.saveas("Results\SEL.xls") 
$a.quit

Answer : Powershell saveas xls directory

I do not understand how Excel automation works, it was always a bit of a chaos for me, but here is a workaround (insert it over line 8):

$fs = New-Object -ComObject scripting.filesystemobject
$absolutepath = $fs.GetAbsolutePathName("\Results\SEL.xls")
$b.saveas($absolutepath)
Random Solutions  
 
programming4us programming4us