Wednesday, February 8, 2012

Self Running PowerShell File

Will ( and I had some email back and forth today about custom installers using PowerShell.  In this correspondence, I was trying to think of the most intuitive way to execute a PowerShell script on an unknown system.

One of these, I thought was academically interesting... and Hence, the PowerShell batch script.

Save this to a batch file : Test.bat

copy %~dpn0.BAT %~dpn0.ps1
powershell.exe -Noprofile -ExecutionPolicy Unrestricted -file %~dpn0.ps1
@DEL %~dpn0.ps1

Now the issue is that it is making a copy of itself.... but it will run.

- EDIT - Had an error at work, see