Running PowerShell within a SQL Agent job

  • I've been staring at this all day, so I'm sorry if the answer to this is really obvious :-).

    I'm creating a SQL Agent job that runs a PowerShell script against our Central Management Server (on the same instance as the job) to evaluate policies across our SQL estate. It's based on the Enterprise Policy Management Framework here: https://epmframework.codeplex.com/

    The PowerShell script works perfectly when executed on its own, and the SQL Agent job containing the script also works perfectly when running under a proxy using my credentials (because I'm an admin), but not under the normal SQL Agent account, when the job "succeeds" but produces this error message in the Job History:

    The error information returned by PowerShell is: 'SQL Server PowerShell provider error: Failed to read child items. [The pipeline has been stopped.] The pipeline has been stopped. ' A job step received an error at line 260 in a PowerShell script. The corresponding line is 'Get-ChildItem | Where-Object {$_.Name -eq $Policy.Name} | Invoke-PolicyEvaluation -TargetServerName $ServerName -AdHocPolicyEvaluationMode $EvalMode -OutputXML > $OutputFile '. Correct the script and reschedule the job.

    The script in question is referenced by the PowerShell script in the SQL Agent job, and works perfectly when run under my own account, so I don't think it's an issue with the script itself, and it must be something to do with permissions (?)

    Rather than elevating the permissions of the existing SQL Agent account, I want to request a new account so the proxy can use its credentials instead of mine. What are the minimum permissions this account will need to run the job which executes the PowerShell to evaluate policies against other instances via my CMS?

    I hope that made sense! Thanks in advance.

  • I just my scripts into a PS1 file and create an os exec job step calling the PS1 script and passing any parameters

    -----------------------------------------------------------------------------------------------------------

    "Ya can't make an omelette without breaking just a few eggs" 😉

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply