我使用具有管理員角色的用戶。但是,默認情況下,腳本以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