Add a script for rebooting the computer
This commit is contained in:
parent
be4ee90f7d
commit
bb3ea5d555
1 changed files with 48 additions and 0 deletions
48
scripts/Windows/Scripts/PowerManagement.ps1
Normal file
48
scripts/Windows/Scripts/PowerManagement.ps1
Normal file
|
@ -0,0 +1,48 @@
|
|||
using namespace Microsoft.Win32;
|
||||
. "$PSScriptRoot/Scripting.ps1";
|
||||
|
||||
$null = New-Module {
|
||||
[RegistryKey] $key = $null;
|
||||
$runOncePath = "HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce";
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Gets the reghistry key containing the `RunOnce` commands.
|
||||
#>
|
||||
function Get-RunOnceKey {
|
||||
Get-Item $runOncePath;
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Registers a task to run the setup once after the next reboot.
|
||||
|
||||
.PARAMETER UserKey
|
||||
The regtistry key of the user to register the task for.
|
||||
#>
|
||||
function Register-Setup {
|
||||
param(
|
||||
[RegistryKey] $UserKey
|
||||
)
|
||||
|
||||
$key = Get-RunOnceKey $UserKey;
|
||||
|
||||
Set-ItemProperty -Path $key.PSPath -Name $runOnceName -Type "ExpandString" -Value `
|
||||
"pwsh -Command " + `
|
||||
"`$env:PWSH_PATH = $(ConvertTo-Injection $env:PWSH_PATH);" + `
|
||||
"`$env:INSTALLER_SCRIPT = $(ConvertTo-Injection $env:INSTALLER_SCRIPT);" + `
|
||||
"`$env:CONFIG_MODULE = $(ConvertTo-Injection $env:CONFIG_MODULE);" + `
|
||||
"& `$env:INSTALLER_SCRIPT;";
|
||||
|
||||
$key.Handle.Close();
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Reboots the machine intermediately and restarts the setup after the next login.
|
||||
#>
|
||||
function Restart-Intermediate {
|
||||
Register-Setup;
|
||||
Restart-Computer;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue