patternsqlMinor
Execute Remote Powershell script from SQL Agent
Viewed 0 times
scriptsqlpowershellagentremotefromexecute
Problem
A test
Example:
The agent account has been given access also.
This test file currently does something very basic: displays a string.
When it runs, it does not show an error message, because it just does not respond. Do you have any idea about what is happening, or which security settings are missing?
SQL Server job hangs when it executes a Powershell script. It does work using my login and a Powershell window, but not using the Agent account and a job. The SQL Agent user has read/write/execute permissions to the directory with the powershell script.Example:
Run as: SQL Server Agent Service Account
powershell.exe -file \\Server02\test2\Test.ps1The agent account has been given access also.
This test file currently does something very basic: displays a string.
When it runs, it does not show an error message, because it just does not respond. Do you have any idea about what is happening, or which security settings are missing?
Solution
JNK was correct in the comment above. If I ran it in the command shell, there was a prompt saying
Security Warning Run only scripts that you trust
In order to avoid this message, I added -ExecutionPolicy Bypass to the command
Example:
powershell.exe -ExecutionPolicy Bypass -file \Server02\test2\Test.ps1
The job is now able to complete.
Security Warning Run only scripts that you trust
In order to avoid this message, I added -ExecutionPolicy Bypass to the command
Example:
powershell.exe -ExecutionPolicy Bypass -file \Server02\test2\Test.ps1
The job is now able to complete.
Context
StackExchange Database Administrators Q#84126, answer score: 4
Revisions (0)
No revisions yet.