Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am performing a job from SQL server agent with a powershell command.

It was running fine a couple of days back.. there is no change in the script.

The script is also working fine if i run it via powershell.exe

Now when i run the same job its not working.... Below is the script which does a simple job of refreshing data via a macro an excel n save it as another workbook.

i get this error

A job step received an error at line 2 in a PowerShell script. The corresponding line is '$Excel = New-Object -ComObject Excel.Application'. Correct the script and reschedule the job

Script

$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $true
$Excel.DisplayAlerts = $false
############## Working with Workbooks #############

$Excel.Workbooks.Open("C:\Users\dashboard\Dropbox\SMX Data\India\Data Flat Files\IntCreditors.xlsm")
$Excel.run("AutoUpdate")
$Excel.Workbooks.item("IntCreditors.xlsm").SaveAs("C:\Users\dashboard\Dropbox\SMX Data\India\Data Flat Files\IntCreditors.xlsm")
$Excel.Workbooks.Close()
$Excel.Quit()
Get-Process excel | Stop-Process -Force
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel)

Please help

share|improve this question

closed as off-topic by Max Vernon, Colin 't Hart, Mark Storey-Smith, RolandoMySQLDBA, Shanky Jun 1 at 4:10

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – Max Vernon, RolandoMySQLDBA
If this question can be reworded to fit the rules in the help center, please edit the question.

2  
I'm voting to close this question as off-topic because it should have been migrated to StackOverflow... –  Colin 't Hart May 29 at 21:23