如何确定我当前的 PowerShell 控制台是否运行提升(以管理员身份)

How can I find out whether my current PowerShell console runs elevated (as administrator)

是否有 cmdlet 或其他方法可以查明我当前的 PowerShell 控制台是否以管理员身份运行,即提升?

试试这个代码:

if ((New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { 
Write-Host "Elevated." 
} else { 
Write-Host "Not elevated." 
}

归因:https://www.itprotoday.com/powershell/check-elevation-powershell