在Powershell中删除QADObject需要交互.需要一条出路



我正在尝试编写一个powershell脚本来删除非常旧的AD帐户。

它是有效的,但当我从PowershellGUI运行它时,它会提示您单击yes/no。我查阅了PowerGUI的Remove-QADObject文档,但没有提到静默模式。有人知道附近的工作吗?

# 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-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
}

最新更新