Intune Win32 & Powershell

I did not find the complete story anywhere so I put this together so it would be easier for others to get PS and Intune making nice.

I expect some familiarity with Intune and Win32 apps, as I will skip most of the pretext.

As most of you know creating Win32 apps one needs to use this project on github. Then just put your stuff in a folder and point the tool at that.

This is the structure I have found works best:

Copy your script into the folder, for this example we just call it Script.ps1.

Create a Run.cmd file in the same folder with the following content:

Make sure there is no lineshift in front of the ELSE statement.

Use the following structure for the Script.ps1:

The Exit <value> will set the %ERRORLEVEL% variable in the cmd, and calling exit on this in the cmd will make sure the exit code get’s handed over to Intune.

Another trick the cmd is doing (as intune will run up a 32bit cmd) is to make sure a 64bit PS session will start as I figure there is not many 32bits installations of Win10 left.
Though running in 32 bit PS, stuff like talking to the registry does not work.

Happy tinkering!

Leave a Comment

Your email address will not be published. Required fields are marked *