I spitted the steps of my setup script into different functions. I want to be able to stop the script sometime. If I restart the script it should continue the last step where I stopped. So I logged the last step in a Tempfile. If I start the script it reads the tempfiles last logged step and jumps to that step on restart.
Function Step1 {
Set-Content -Path $TEMPFILE -value "Step1" #"Setting current step" into a temp file
do first stuff #part in th function. e.g. copy files, add access rights...
Step2 #calling the next function
}
Function Step2 {
Set-Content -Path $TEMPFILE -value "Step2"
do second stuff
Step3...
}
...Step 25
On Startup the script checks if a Tempfile is existing and add the last step into a variable[String]
Is there any way to get this String Variable into a "Jump To Function" Sequence? like:...
If ($GETSTEP){
Write-Host "Continuing with $GETSTEP"
$GOTO = ${function:GETSTEP}
&GOTO
}else{
Write-Host "GET STARTET"
Step1
}
PowerShell version 5.1.14393.3471 ...