03-22-2023 09:23 AM
Hello,
I am trying to call powershell script from mipm when package is installed.
Path to powershell script should be calcultaed from SystemDrive macro.
Content of instructions file generated from nipb is the following:
<instructions>
<targetAttributes/>
<shortcuts/>
<customExecutes>
<customExecute root="BootVolume" exeName="Windows\System32\WindowsPowerShell\v1.0\powershell.exe" arguments=""%SystemDrive%\my nice dir\script.ps1"" hideConsoleWindow="n" ignoreErrors="n" schedule="post" step="install" wait="y"/>
</customExecutes>
</instructions>
I can notice that powershellwindow opens, but my script does not execute
Is there something obvious that i am missing?
Solved! Go to Solution.
03-22-2023 09:29 AM
Double check that PowerShell script execution is enabled. Windows by default does not allow PowerShell scripts to run and needs to be enabled. Hopefully your IT allows you to enable it. I personally have just used cmd.exe and batch files to automate some actions in NI Packages.
03-22-2023 09:30 AM
Thanks for reply, script execution is enabled. I can run this script by hand and it works.
03-22-2023 09:35 AM
Just to make sure, a small detail to add: does the user account that starts the installation using NIPM also have elevated privileges (aka Admin)?
03-22-2023 12:50 PM - edited 03-22-2023 01:47 PM
It seems that the command prompt is more forgiving, not sure why. In my test I was able to get the following working from a command prompt:
powershell.exe -Command ". 'c:\temp\my temp\test file.ps1'"
So then I was able to get the following custom execute working from a package instructions file:
<customExecute root="BootVolume" exeName="Windows\System32\WindowsPowerShell\v1.0\powershell.exe" arguments="-Command ". 'c:\temp\my temp\test file.ps1'"" step="install" schedule="pre" wait="y" ignoreErrors="n" hideConsoleWindow="n" />
So try the following for you command in your instructions file:
<customExecute root="BootVolume" exeName="Windows\System32\WindowsPowerShell\v1.0\powershell.exe" arguments="-Command ". '%SystemDrive%\my nice dir\script.ps1'"" hideConsoleWindow="n" ignoreErrors="n" schedule="post" step="install" wait="y"/>
[Edit] I was also able to get the following to work:
powershell.exe -File "c:\temp\my temp\test file.ps1" "argument1" "argument2"
So the instructions file would look like this:
<customExecute root="BootVolume" exeName="Windows\System32\WindowsPowerShell\v1.0\powershell.exe" arguments="-File "c:\temp\my temp\test file.ps1" "argument1" "argument2"" step="install" schedule="pre" wait="y" ignoreErrors="n" hideConsoleWindow="n" />
03-23-2023 02:38 AM
Thanks, problem solved.
I did not know -File or -Command param is required when calling script