2013-02-15 54 views
-1

我想寫一個PowerShell腳本來刪除非常舊的AD帳戶。Powershell中的Remove-QADObject需要交互。需要一個出路

它可以工作,但是當我從PowershellGUI運行它時,它會提示您單擊yes/no。我查看了PowerGUI's Remove-QADObject documentation,但沒有提到靜音模式。有沒有人知道解決方法?

# Get the date that is about 6 months ago from today. 
$dateObj = (Get-Date).AddDays(-180) 

$oldADUsers = Get-QADUser -SearchRoot "OU=expired_test,OU=Students,DC=..." -AccountExpiresBefore $dateObj 

foreach ($user in $oldADUsers) 
{ 
    Remove-QADObject $user 
} 

回答

1

嘗試使用-Force-Confirm:$false-Confirm:$false通知該cmdlet不提示進行確認。可能不需要-Force,但它有時是必需的。我沒有QAD模塊來測試它是否需要在這裏,但它將不會造成任何傷害。

# Get the date that is about 6 months ago from today. 
$dateObj = (Get-Date).AddDays(-180) 

$oldADUsers = Get-QADUser -SearchRoot "OU=expired_test,OU=Students,DC=..." -AccountExpiresBefore $dateObj 

foreach ($user in $oldADUsers) 
{ 
    Remove-QADObject $user -Force -Confirm:$false 
} 
+0

謝謝!星期一早上試試吧!非常感謝。 – user1866880 2013-02-15 18:26:10