27 lines
689 B
PowerShell
27 lines
689 B
PowerShell
$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'
|