Self-elevate OpenSSH overwrite script
This commit is contained in:
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
The repository root contains `.\overwrite_openssh_license.ps1`.
|
The repository root contains `.\overwrite_openssh_license.ps1`.
|
||||||
|
|
||||||
The script overwrites `C:\Windows\System32\OpenSSH\LICENSE.txt` with:
|
The script relaunches itself elevated when needed, then overwrites
|
||||||
|
`C:\Windows\System32\OpenSSH\LICENSE.txt` with:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
hello world
|
hello world
|
||||||
|
|||||||
@@ -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'
|
$targetPath = 'C:\Windows\System32\OpenSSH\LICENSE.txt'
|
||||||
|
|
||||||
Set-Content -Path $targetPath -Value 'hello world'
|
Set-Content -Path $targetPath -Value 'hello world'
|
||||||
|
|||||||
Reference in New Issue
Block a user