NI Package Manager (NIPM)

cancel
Showing results for 
Search instead for 
Did you mean: 

NIPM - call powershell script after install

Solved!
Go to solution

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="&quot;%SystemDrive%\my nice dir\script.ps1&quot;" hideConsoleWindow="n" ignoreErrors="n" schedule="post" step="install" wait="y"/>
	</customExecutes>
</instructions>

 

pawhan11_0-1679494847066.png

 

I can notice that powershellwindow opens, but my script does not execute

Is there something obvious that i am missing?

0 Kudos
Message 1 of 6
(3,381 Views)

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.

__________________________________
Bill Eisenhower
Certified LabVIEW & TestStand Developer
0 Kudos
Message 2 of 6
(3,377 Views)

Thanks for reply, script execution is enabled. I can run this script by hand and it works.

0 Kudos
Message 3 of 6
(3,374 Views)

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)?

 

0 Kudos
Message 4 of 6
(3,367 Views)
Solution
Accepted by topic author pawhan11

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 &quot;. 'c:\temp\my temp\test file.ps1'&quot;" 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 &quot;. '%SystemDrive%\my nice dir\script.ps1'&quot;" 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 &quot;c:\temp\my temp\test file.ps1&quot; &quot;argument1&quot; &quot;argument2&quot;" step="install" schedule="pre" wait="y" ignoreErrors="n" hideConsoleWindow="n" />

 

Scott Richardson
https://testeract.com
0 Kudos
Message 5 of 6
(3,340 Views)

Thanks, problem solved. 

I did not know -File or -Command param is required when calling script

0 Kudos
Message 6 of 6
(3,311 Views)