Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Powershell saveas xls directory

Posted on 2010-08-24
2
Medium Priority
?
801 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 1000 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

Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

Question has a verified solution.

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

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 …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 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