# Surviving a reboot

**URL:** <https://forums.powershell.org/t/surviving-a-reboot/8250>\
**Category:** PowerShell Help\
**Created:** [March 17, 2017, 11:46am UTC](https://forums.powershell.org/t/surviving-a-reboot/8250 "2017-03-17T11:46:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rawdogz](https://avatars.discourse-cdn.com/v4/letter/r/58f4c7/32.png) [@rawdogz](https://forums.powershell.org/u/rawdogz)\
**Post date:** [March 17, 2017, 11:46am UTC](https://forums.powershell.org/t/surviving-a-reboot/8250/1 "2017-03-17T11:46:55Z")

</div>

hello everyone,

need a little help on this one. I and trying to write a script that would survive a reboot and resume when the system/server comes backup. I get the following script from . credit to lasse W… I cant seem to get it to work. if i can get it to do what its suppose to do, i can figure out the rest. or if anyone knows a better way to get this accomplished.

```
$global:started = $false
$global:startingStep = $step
$global:RegRunKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run"
$global:restartkey = "Restart-And-Resume"
$global:powershell = (Join-Path $env:windir "system32\windowsPowerShell\v1.0\powershell.exe")

function Test-key([string]$path, [string] $key)
{
	return ((Test-Path $path) -and ((Get-Key $path $key) -ne $null))
}
function Remove-key([string] $path, [string] $key)
{
Remove-ItemProperty -Path $path -Name $key	
}
function Set-Key([string]$path, [string]$key, [string]$value)
{
	Set-ItemProperty -Path $path -Name $key -Value $value
}
function Get-key([string]$path, [string]$key)
{
return (Get-ItemProperty $path).$key	
}

function Restart-And-Resume([string]$script, [string]$step)
{
Restart-and-Run $global:restartkey "$global:powershell $script -Step $step"	
}
function Clear-Any-Restart([string]$key = $global:restartkey)
{
	If (Test-key $global:RegRunKey $key)
	{
		Remove-key $global:RegRunKey $key}
}
function Should-Run-step([string]$prospectStep)
{
	if ($global:startingStep -eq $prospectStep -or $global:started)
	{
		$global:started = $true
	}	
	Return $global:started
	}
function Restart-and-Run([string]$key, [string]$run)
{
	Set-Key $global:RegRunKey $key $run
	Restart-Computer
	exit
	
}

function Wait-for-keypress
{
	$Host.UI.RawUI.ReadKey("IncludeKeyDown") | Out-Null
	$Host.UI.RawUI.FlushInputBuffer()
	
}

param($step = "A")
$script = $MyInvocation.MyCommand.Definition
$scriptPath = Split-Path -Parent $script 
.(Join-Path $scriptPath asjob .ps1)

Clear-Any-Restart

if (Should-Run-step "A")
{
	Write-Host "A"
	Wait-for-keypress " will continue after reboot, press any key "
	Restart-And-Resume $script "B"
}

if (Should-Run-step "B")
{	
Write-Host "B"
}

If (Should-Run-step "C")
{
Write-Host "C"	
}

Wait-for-Keypress "test script complete, press any key to exit"
```

the following are the error i get

The term ‘param’ is not recognized as the name of a cmdlet, function, script fi  
le, or operable program. Check the spelling of the name, or if a path was inclu  
ded, verify that the path is correct and try again.  
At C:\Users\Dev\Desktop\Script Test Area\asjob.ps1:62 char:6

- param \<\<\<\< ($step = "A")
  - CategoryInfo : ObjectNotFound: (param:String) , CommandNotFou  
ndException
  - FullyQualifiedErrorId : CommandNotFoundException

Join-Path : A positional parameter cannot be found that accepts argument '.ps1'  
.  
At C:\Users\Dev\Desktop\Script Test Area\asjob.ps1:65 char:12

- .(Join-Path \<\<\<\< $scriptPath asjob .ps1)
  - CategoryInfo : InvalidArgument: (🙂 [Join-Path], ParameterBindi  
ngException
  - FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell  
.Commands.JoinPathCommand

thank you

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [March 17, 2017, 12:27pm UTC](https://forums.powershell.org/t/surviving-a-reboot/8250/2 "2017-03-17T12:27:26Z")

</div>

I never say this but consider workflow. This is exactly why it exists.

---

<div class="post-metadata">

**Author:** ![rawdogz](https://avatars.discourse-cdn.com/v4/letter/r/58f4c7/32.png) [@rawdogz](https://forums.powershell.org/u/rawdogz)\
**Post date:** [March 17, 2017, 1:18pm UTC](https://forums.powershell.org/t/surviving-a-reboot/8250/3 "2017-03-17T13:18:21Z")

</div>

from what i read workflow will only work on window 8 and R2 2012.

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [March 17, 2017, 1:19pm UTC](https://forums.powershell.org/t/surviving-a-reboot/8250/4 "2017-03-17T13:19:59Z")

</div>

No. It’s a core feature of PowerShell v3.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:39pm UTC](https://forums.powershell.org/t/surviving-a-reboot/8250/5 "2024-05-16T20:39:29Z")

</div>


