Self-elevate OpenSSH overwrite script

This commit is contained in:
2026-03-15 14:40:38 +01:00
parent 2b3e836c47
commit b13fdb492e
2 changed files with 25 additions and 1 deletions

View File

@@ -1,3 +1,26 @@
$currentIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
$currentPrincipal = [Security.Principal.WindowsPrincipal]::new($currentIdentity)
$isElevated = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isElevated)
{
$shellPath = Join-Path $PSHOME 'pwsh.exe'
if (-not (Test-Path $shellPath))
{
$shellPath = 'powershell.exe'
}
Start-Process -FilePath $shellPath -Verb RunAs -ArgumentList @(
'-ExecutionPolicy',
'Bypass',
'-File',
$PSCommandPath
)
exit
}
$targetPath = 'C:\Windows\System32\OpenSSH\LICENSE.txt'
Set-Content -Path $targetPath -Value 'hello world'