asked on
$Count = 0
$Filter = [ScriptBlock]::Create({Name -like $($Computer.computer)+"-*"})
$Computers = Import-CSV "C:\Input.csv"
ForEach ($Computer in $Computers) {
#If computer is found, delete, else skip it.
Try {
Remove-ADComputer -Filter $Filter
Start-Sleep -Milliseconds 700
$Count ++
}
Catch {
"Computer Not Found: $($Computer.computer)"
}
}
"Count is: $Count"
ASKER
ASKER
Active Directory (AD) is a Microsoft brand for identity-related capabilities. In the on-premises world, Windows Server AD provides a set of identity capabilities and services, and is hugely popular (88% of Fortune 1000 and 95% of enterprises use AD). This topic includes all things Active Directory including DNS, Group Policy, DFS, troubleshooting, ADFS, and all other topics under the Microsoft AD and identity umbrella.
TRUSTED BY
ASKER
I got rid of the scriptblock, and opted for appending "-P" to a variable called $Name before passing it to Remove-ADComputer. In case of error, "-W" will be added to $Name and then that will get passed to Remove-ADComputer to attempt deletion:
Open in new window