簡體   English   中英

在 AD 中創建計算機對象后,需要借助 Powershell 腳本將 Active Directory 中的計算機對象移動到新的 OU

[英]Need Assistance With a Powershell Script to Move a Computer Object in Active Directory to New OU As Soon as the Computer Object Gets Created in AD

我有一個腳本可以在我的 VMware 環境中部署一個新的 VM。 一旦計算機對象進入 Active Directory 中的默認“計算機”OU,我希望腳本立即將計算機對象移動到不同的 OU。 嘗試通過睡眠來計時是很困難的,因為每次運行腳本時構建 VM 的時間都不同,除非將計算機對象移出默認的“計算機”,否則其他需要運行的任務將無法成功執行其工作OU 到不同的指定 OU 立即。 任何關於如何實現這一點的想法將不勝感激!

您可以嘗試使用 do-until:

write-host "************ Creating $ServerName; DO NOT CLOSE/STOP THIS SCRIPT! ************nn" -f yellow 
do { 
    write-host "." -nonewline -f red 
    Start-Sleep 3
    } 
until(Get-ADComputer -identity $servername -ErrorAction SilentlyContinue) 
$serverdn = (Get-ADComputer -identity $servername).distinguishedname 
Move-ADObject -identity $serverdn -TargetPath $fullpath

在將服務器加入域之前,您還可以嘗試在正確的 OU 中預先安排您的計算機帳戶

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM