Tuesday, April 12, 2016

How to make a PowerShell script do it's thing in a different console window!

Below the prompts to press a key represent the real work to be done and the rest of this is the dress up around that to stage it:

#WHAT IS THIS THING? HOW DO I GET IT TO WORK?
 
#1. run Powershell as an administrator
#2. navigate to the folder which holds helper.ps1 or put the helper.ps1 file in the folder
      suggested at the command prompt
#3. run the command: powershell.exe -executionpolicy unrestricted
#4. run the command: .\helper.ps1
 
 
param([Int32]$step=1)
if($step -eq 2)
{
   echo "press (almost) any key to start"
   cmd /c pause | out-null
   echo "press (almost) any key to end"
   cmd /c pause | out-null
}
else
{
   $invocation = (Get-Variable MyInvocation).Value
   $directorypath = Split-Path $invocation.MyCommand.Path
   Start-Process powershell -ArgumentList "-file $directorypath\helper.ps1 -step 2"
}

No comments:

Post a Comment