Quantcast
Viewing all articles
Browse latest Browse all 1519

Powershell fails when scheduled as a job

This works through powershell. 
I have other jobs that use powershell script that also connect to the same servers using the same powershell proxy account that work fine.

Error:

Executed as user: domain\proxy_account. A job step received an error at line 23 in a PowerShell script. The corresponding line is '        foreach ($job in $srv.Jobserver.Jobs)  '. Correct the script and reschedule the job. The error information returned by PowerShell is: 'The following exception occurred while trying to enumerate the collection: "An exception occurred while executing a Transact-SQL statement or batch.".  '. Process Exit Code -1.  The step failed.

Script excerpt:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null;
$params = @{'server'='sql_server_name';
       'Database'='database_name'}
$sqlservers = invoke-sqlcmd @params -Query "SELECT InstanceName from SQLInstances_TEST"
foreach($sqlserver in $sqlservers)
{
        foreach ($job in $srv.Jobserver.Jobs)
        {
...

Thank you, any clues much appreciated.


Paula


Viewing all articles
Browse latest Browse all 1519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>