因此,我正試圖為我在Powershell中遇到的一個問題創建一個解決方案。
我需要想出一個辦法,讓我的腳本檢查它是否以管理權限運行過。如果不是,它需要以管理員權限重新運行。
我的情況與其他被問到的情況不同(從我查到的所有帖子中),因為我們的普通用戶賬戶沒有權限,所以我需要輸入其他憑證。
如果這有幫助的話,我們的管理賬戶在名稱中確實有一個結尾的識別符號,如果我們能過濾掉這一點的話。例如。"John.Doe.A "和.A表示這是一個管理帳戶。
uj5u.com熱心網友回復:
繼續我的評論。
你的情況并不獨特。它在這里和其他許多地方都被問及。
'powerhell SecretManagement模塊'自動提升
示例命中:
您在 "Windows憑證管理器 "中存盤所需的憑證,并在需要時從其中呼叫。MS甚至為這種使用情況提供了一個新的Secrets模塊。更多細節請參見MS檔案中的主題。
像這樣:
SecretManagement 和 SecretStore 是通用的
SecretManagement 和 SecretStore 是通用的。
https://devblogs.microsoft.com/powershell/secretmanagement-and-secretstore-are-generally-available
還有這個:
Microsoft.PowerShell.SecretManagement
Get-Secret
Get-SecretInfo
Get-SecretVault
注冊-SecretVault
移除-Secret
Set-Secret
Set-SecretInfo
Set-SecretVaultDefault
測驗-SecretVault
取消注冊-SecretVault
uj5u.com熱心網友回復:
使用這個。
$adminrole = ([Security.Principal.WindowsBuiltInRole] " Administrator")
$wid = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()
If(-not $wid.IsInRole($adminrole)){
$newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell"
$newProcess.Arguments = $myInvocation.MyCommand.Definition
$newProcess.Verb = "runas"。
[System.Diagnostics.Process]::Start($newProcess)。
exit。
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/326679.html
標籤:
