Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Not moving within the switch

$
0
0

I am trying to display a message and restart and display a second message. My problem is that it wont get past the 1st part of the switch, it just keeps looping over and over.

param($global:Step=1)
function Set-NextStep() {
  $global:Step++
  Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "SystemSetupStep" -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\test\test -Step $global:Step"
}
function Run-NextStep() {
  switch ($global:Step) {
    1 { Step-1 }
    2 { Step-2 }
    default { Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" -Name "SystemSetupStep" }
  }
}
function Step-1() {
  Write-Host "This is step 1"
  Set-NextStep
  Restart-Computer
}
function Step-2() {
  Write-Host "This is step 2"
  Set-NextStep
  Run-NextStep
}
Run-NextStep


Viewing all articles
Browse latest Browse all 21975

Trending Articles