Centralize script for rebooting

This commit is contained in:
Manuel Thalmann 2023-06-22 22:58:54 +02:00
parent 249b4d531c
commit 0f75bd3098
2 changed files with 7 additions and 1 deletions

View file

@ -12,7 +12,7 @@ function Invoke-Upgrade([Context] $context)
Write-Information "A Reboot is Required!";
Write-Information "Windows will reboot now and the installation will be continued automatically.";
$null = New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name "PortValhalla" -Value "pwsh `"$($context.EntryPoint)`"" -PropertyType ExpandString;
Restart-Computer;
$context.Reboot();
exit;
}
elseif ((Get-WindowsUpdate -IgnoreReboot).Count -gt 0)

View file

@ -61,4 +61,10 @@ class Context {
$null = New-Item -ItemType Directory $tempDir;
return $tempDir;
}
[void] Reboot() {
Write-Host "Restarting Computer...";
$null = New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce" -Name "PortValhalla" -Value "pwsh `"$($this.EntryPoint)`"" -PropertyType ExpandString;
Restart-Computer;
}
}