0

Azure WebJobs run Powershell scripts, but Invoke-Sqlcmd fails in WebJob. How to fix? Script works in PowerShell ISE locally but fails in Azure Webjob:

    $result = Invoke-Sqlcmd -Query 'SELECT AlertLine FROM HR.AlertRecordsOpenInline;' `
    -ServerInstance 'xxxxxxxx.database.windows.net' `
    -Username 'xxxxx@xxxxxx' -Password 'xxxxxx' -Database 'xxxxxx'
foreach($item in $result){
    [string]$Results += ($item.AlertLine)
    }
$Results

WebJob Run Details Output:

[09/02/2016 16:09:00 > da15b0: SYS INFO] Status changed to Initializing
[09/02/2016 16:09:00 > da15b0: SYS INFO] Run script 'Invoke-Sqlcmd.ps1' with script host - 'PowerShellScriptHost'
[09/02/2016 16:09:00 > da15b0: SYS INFO] Status changed to Running
[09/02/2016 16:09:01 > da15b0: ERR ] Invoke-Sqlcmd : The term 'Invoke-Sqlcmd' is not recognized as the name of a 
[09/02/2016 16:09:01 > da15b0: ERR ] cmdlet, function, script file, or operable program. Check the spelling of the 
[09/02/2016 16:09:01 > da15b0: ERR ] name, or if a path was included, verify that the path is correct and try again.
[09/02/2016 16:09:01 > da15b0: ERR ] At D:\local\Temp\jobs\triggered\Invoke-Sqlcmd\ni4ywn1l.sgn\Invoke-Sqlcmd.ps1:1 
[09/02/2016 16:09:01 > da15b0: ERR ] char:11
[09/02/2016 16:09:01 > da15b0: ERR ] + $result = Invoke-Sqlcmd -Query 'SELECT AlertLine FROM 
[09/02/2016 16:09:01 > da15b0: ERR ] HR.AlertRecordsOpenInline; ...
[09/02/2016 16:09:01 > da15b0: ERR ] +           ~~~~~~~~~~~~~
[09/02/2016 16:09:01 > da15b0: ERR ]     + CategoryInfo          : ObjectNotFound: (Invoke-Sqlcmd:String) [], Comma 
[09/02/2016 16:09:01 > da15b0: ERR ]    ndNotFoundException
[09/02/2016 16:09:01 > da15b0: ERR ]     + FullyQualifiedErrorId : CommandNotFoundException
[09/02/2016 16:09:01 > da15b0: ERR ]  
[09/02/2016 16:09:01 > da15b0: SYS INFO] Status changed to Success

Have searched and searched but am stuck, not sure what to try next. Thank you in advance for your help!

1 Answer 1

1

The SQLPS module is not installed in the Azure WebJobs environment and I'm not aware of a way to install additional modules. Have you tried Azure Automation, if it doesn't have the modules you need you can add your own or install modules from the gallery.

Sign up to request clarification or add additional context in comments.

1 Comment

Runbooks in Azure Automation are the solution - thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.