July 10, 2013 at 11:53 am
Hi everyone.
I have a powershell script that lists all backup status across various servers.
Script runs fine via Powershell gui (Normally)
Sometimes I see an issue. Think it is regarding Excel and how it outputs its results.
I can see that when the spreadsheet is created, it leaves the excel.exe*32 running on my machine.
Unless I close that , or go into spreadsheet and exit it, subsequent runs also fail.
When not there , runs fine.
However when run as SQL agent job it always fails.
this is the error.
A job step received an error at line 88 in a PowerShell script.
The corresponding line is '$Excel.SaveAs("Y:\SQL\Failedjobs.xlsx")'.
Correct the script and reschedule the job.
The error information returned by PowerShell is:
'Exception calling "SaveAs" with "1" argument(s): "SaveAs method of Workbook class failed"
Any tips on how to correct this , or what I am doing wrong and need to check ?
many thanks
July 10, 2013 at 12:22 pm
I can't answer the question you asked, sorry, but I would have done this with SSIS instead.. YMMV
CEWII
July 10, 2013 at 7:55 pm
Is the server 64-bit? Does the server have the Excel Object Model installed either via Office or VSTO? How are you kicking off the script, in a PowerShell step-type or using powershell.exe in a CmdExec step-type?
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
July 10, 2013 at 11:13 pm
opc.three (7/10/2013)
Is the server 64-bit? Does the server have the Excel Object Model installed either via Office or VSTO? How are you kicking off the script, in a PowerShell step-type or using powershell.exe in a CmdExec step-type?
HI , the machine is 64 bit and assume has Excel object model installed as it runs from powershell gui fine. As long as Excel.exe is still not running.
Trying to Kick it off via a SQL job. Never worked so far , but script does work in gui as long as above is met.
July 10, 2013 at 11:57 pm
with regards to your Powershell script:
do you actually use an xlsx template to fill out with your data?
do you actually use any excel functionallity at all ?
if not: just change the powershell to save your data as CSV !
pro:
- you don't need to have office parts installed on your sever
- opened by a client that has excel installed, the csv file will be opened by it.
con:
- when opened by excel, it will not format the columns by default ( meaning column width, color, font,...)
use e.g.
# export data to csv sorted by ServerName, DbName, Name in ascending order
$drAllRslt | Sort-Object ServerName, DbName, Name | export-csv -path "D:\SQLAgentResults\Reslut123.csv" -NoTypeInformation
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
July 11, 2013 at 1:49 am
ALZDBA (7/10/2013)
with regards to your Powershell script:do you actually use an xlsx template to fill out with your data?
do you actually use any excel functionallity at all ?
if not: just change the powershell to save your data as CSV !
pro:
- you don't need to have office parts installed on your sever
- opened by a client that has excel installed, the csv file will be opened by it.
con:
- when opened by excel, it will not format the columns by default ( meaning column width, color, font,...)
use e.g.
# export data to csv sorted by ServerName, DbName, Name in ascending order
$drAllRslt | Sort-Object ServerName, DbName, Name | export-csv -path "D:\SQLAgentResults\Reslut123.csv" -NoTypeInformation
Johan
Thanks for that. I am still trying to learn powershell. Could I post the code I am using and then could you show me where I need to change it in order for it work with your suggested changes ?
July 11, 2013 at 1:50 am
ALZDBA (7/10/2013)
with regards to your Powershell script:do you actually use an xlsx template to fill out with your data?
do you actually use any excel functionallity at all ?
if not: just change the powershell to save your data as CSV !
pro:
- you don't need to have office parts installed on your sever
- opened by a client that has excel installed, the csv file will be opened by it.
con:
- when opened by excel, it will not format the columns by default ( meaning column width, color, font,...)
use e.g.
# export data to csv sorted by ServerName, DbName, Name in ascending order
$drAllRslt | Sort-Object ServerName, DbName, Name | export-csv -path "D:\SQLAgentResults\Reslut123.csv" -NoTypeInformation
Johan
Thanks for that. I am still trying to learn powershell. Could I post the code I am using and then could you show me where I need to change it in order for it work with your suggested changes ?
July 12, 2013 at 8:27 am
MickyD (7/10/2013)
opc.three (7/10/2013)
Is the server 64-bit? Does the server have the Excel Object Model installed either via Office or VSTO? How are you kicking off the script, in a PowerShell step-type or using powershell.exe in a CmdExec step-type?HI , the machine is 64 bit and assume has Excel object model installed as it runs from powershell gui fine. As long as Excel.exe is still not running.
Trying to Kick it off via a SQL job. Never worked so far , but script does work in gui as long as above is met.
Is the PowerShell GUI a 64-bit app? It might be a 32-bit app in which case it would be accessing 32-bit Excel objects. Whereas when running through SQL Agent it is running as a 64-bit process. Bit-ness differences are a very common reason why apps that use Office objects work great when debugging and fail when run on a server.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
July 12, 2013 at 8:41 am
thanks , I will check and report back
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply