Solved

Powershell saveas xls directory

Posted on 2010-08-24
2
747 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now