This is an instruction what you need to do to get PowerShell scripts running on your on-premise NSP. PowerShell script is not supported in cloud installations.
Script folder path
Script must be stored in specific folder according to global settings.
Script folder path will by default look in FileStoragePath\PowerShellScripts. If this FileStoragePath not exists will system use default C:\NSPFiles\PowerShellScripts.
If you want to use other specific folder you need to add setting in GlobalSettings like:
exec app.spSetGlobalSetting 'PowerShellScriptFolderPath', 'C:\NSPPowerShellScripts'
Execution policy
In order to prevent malicious scripts from running on your system, PowerShell enforces an execution policy. To enable for execute PowerShell script from external program you need to set ExecutionPolicy on server. By Default Microsoft supported 4 execution policies which you can use:
•Restricted: Scripts won’t run. Period. (Default setting).
•RemoteSigned: Locally created scripts will run. Scripts that were created on another machine will not run unless they are signed by a trusted publisher. This is recommended policy for NSP.
•AllSigned: Scripts will only run if signed by a trusted publisher (including locally-created scripts).
•Unrestricted: All scripts will run regardless of who created them and whether or not they are signed.
In order to change the execution policy, you need to open PowerShell as an Administrator (the command will fail otherwise) and run the following command:
Set-ExecutionPolicy RemoteSigned
The Set-ExecutionPolicy command will ask to verify that you really want to change the execution policy. Go ahead and select Y for yes.
Read more: https://www.pdq.com/blog/writing-your-first-powershell-script/