Solved

Powershell saveas xls directory

Posted on 2010-08-24
2
781 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
[X]
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
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

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
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

696 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