使用活動目錄進行 Powershell 遠端處理

使用活動目錄進行 Powershell 遠端處理

我可以透過下面的腳本遠端連接到網域控制器,但之後我想運行disable-ADAccount,Get-ADUser命令,但出現錯誤

Get-ADUser : The server has rejected the client credentials.

如何在單一腳本檔案中呼叫活動目錄命令?

$password = ConvertTo-SecureString "Password" -AsPlainText -Force
$cred= New-Object System.Management.Automation.PSCredential ("Lab\dcadmin", $password)
Enter-PSSession -ComputerName dc-01 -Port 5985 -Credential $cred

答案1

試試看:在加入相關網域的電腦上,以滑鼠右鍵按一下 Powershell 開始功能表圖示或捷徑,然後選擇「以管理員身分執行」。輸入網域管理員帳戶的憑證。然後嘗試 Powershell 命令。它們應該在網域管理員帳戶的上下文中運行,並且您應該不會遇到授權問題。

請注意,如果您使用本機管理員帳戶登入加入網域的計算機,這可能不起作用,因為當您選擇「以管理員身分執行」時,它將以本機管理員身分執行,而不提示輸入憑證。以非管理員使用者或網域管理員身分登入電腦。

相關內容