Powershell以管理员模式打开PowerShell控制台而不使用UAC对话框并执行一些任务
问题描述:
我使用具有管理员角色的用户。但是,默认情况下,脚本以UAC模式运行,而不是以管理员身份运行。是否有可能打开PowerShell控制台与PowerShell脚本没有UAC对话框?Powershell以管理员模式打开PowerShell控制台而不使用UAC对话框并执行一些任务
我想提升我想要做如下的任务,但它给了我一个需要出席一个对话框:
# Get the ID and security principal of the current user account
$myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent();
$myWindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($myWindowsID);
# Get the security principal for the administrator role
$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator;
# Check to see if we are currently running as an administrator
if ($myWindowsPrincipal.IsInRole($adminRole))
{
# We are running as an administrator, so change the title and background colour to indicate this
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)";
$Host.UI.RawUI.BackgroundColor = "DarkBlue";
Clear-Host;
}
else {
# We are not running as an administrator, so relaunch as administrator
# Create a new process object that starts PowerShell
$newProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell";
# Indicate that the process should be elevated
$newProcess.Verb = "runas";
# Start the new process
[System.Diagnostics.Process]::Start($newProcess);
# Exit from the current, unelevated, process
Exit;
}
#DOING SOME TASK HERE
然而,这打开了,如果我想它确认UAC对话框以管理员模式打开PowerShell。
我尝试过的另一种方法是在管理员模式下默认打开PowerShell控制台(我使用WS 2012,方法与Windows 10相同)。但是,由于DevOps不允许我这样做,所以我没有权利对系统进行更改。有没有其他方式通过PowerShell脚本来处理这个问题?
答
往哪投票?我请求选民提供相同的理由。 – Rishi
昨天我在短时间内收到了一些降薪 - 不知道那家伙有什么问题或者有人被黑客攻击 – DAXaholic