我有一个包含一些服务器数据的数组并有以下脚本:
Write-Host "`nRemoving servers' accounts from AD:" -ForegroundColor Green
for ($j=0; $j-le $screenObj.Length; $j++)
{if (($screenObj[$j].Domain -ne "Unknown") -and ($screenObj.Where({$_ -ne ""})))
{Try {Remove-ADComputer $screenObj[$j].ServerName -Server $screenObj[$j].Domain -Confirm:$false -WhatIf
Write-Host $screenObj[$j].ServerName "deleted." -ForegroundColor DarkYellow}
Catch {Write-Host $screenObj[$j].ServerName ":" $_.Exception.InnerException.Message -ForegroundColor Red}
}
}
它给了我以下输出:
Removing servers' accounts from AD:
What if: Performing the operation "Remove" on target "CN=Server1,OU=Application - With WINS,OU=Application,OU=W2K3,OU=Servers,OU=MY,DC=corp,DC=mycorp,DC=net".
Server1 deleted.
What if: Performing the operation "Remove" on target "CN=Server2,OU=Application - With WINS,OU=Application,OU=W2K3,OU=Servers,OU=MY,DC=corp,DC=mycorp,DC=net".
Server2 deleted.
What if: Performing the operation "Remove" on target "CN=Server3,OU=IIS,OU=W2K8,OU=Servers,OU=Europe,DC=TKMAXX,DC=mycorp,DC=net".
Server3 deleted.
What if: Performing the operation "Remove" on target "CN=Server4,OU=IIS,OU=W2K8,OU=Servers,OU=Europe,DC=TKMAXX,DC=mycorp,DC=net".
Server4 deleted.
: The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
我无法确定为什么输出中的最后一行会出现,因为
: The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
有人可以解释这一点并帮助我解决这个未知警告吗?
另外,请让我知道是否有更好的方法来实现所需的输出。
注意:我正在使用-WhatIf
选项,以便实际上不会删除服务器。