标签: elevated

从提升的提示运行未提升的命令?

是否可以从提升的权限运行的批处理文件中运行没有提升权限的命令?

windows elevation cmd.exe elevated

7
推荐指数
2
解决办法
2494
查看次数

以不同用户身份运行 PowerShell 脚本并提升权限

我知道这看起来像是一个重复的问题,但我已经尝试过这些解决方案,但它们对我不起作用。

我们需要使用我们的域帐户运行脚本,但也要提升执行它的权限。这在大多数设备上都不是问题,因为快捷方式以管理员身份运行并提示我们输入凭据。但是,如果用户是本地管理员,则不会提示我们输入凭据(只是提示是/否 UAC)。

我很困惑为什么这不起作用:

# Get identity of script user
$identity = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()

# Elevate the script if not already
if ($identity.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    Write-Host -F Green 'ELEVATED'
} else {
    Start-Process PowerShell -Verb RunAs "-NoProfile -ExecutionPolicy Bypass -Command `"& '$PSCommandPath'`""
    Exit
}

# Ensure the script has domain privileges
if ($identity.IsInRole('[domain]\[admin group]')) {
    Write-Host -F Green 'DOMAIN ADMIN'
} else {
    Start-Process PowerShell -Verb RunAsUser "-NoProfile -ExecutionPolicy Bypass -Command `"& '$PSCommandPath'`""
    Pause # required, otherwise the Exit below closes the …
Run Code Online (Sandbox Code Playgroud)

powershell elevated

3
推荐指数
1
解决办法
8万
查看次数

标签 统计

elevated ×2

cmd.exe ×1

elevation ×1

powershell ×1

windows ×1