Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Powershell saveas xls directory

Posted on 2010-08-24
2
765 Views
Last Modified: 2012-08-14
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


       
$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

Open in new window

0
Comment
Question by:kabaam
2 Comments
 
LVL 13

Accepted Solution

by:
soostibi earned 250 total points
ID: 33515429
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)
0
 
LVL 11

Author Comment

by:kabaam
ID: 33515529
sweet.  Thanks a bunch.  I removed the first \ in the path and the file saved exactly where I wanted it to go.  I need to remember the getabsolute...

Also, thanks for the quick reply.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A procedure for exporting installed hotfix details of remote computers using powershell
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question