I have an array of computer objects which need to be deleted from Active Directory. This is going to be setup as a scheduled task, so I will not be able to interact with the script once it is fully deployed. I am doing my testing within PowerShell ISE and the following are the steps I have gone through so far.
1)
foreach ($computer in $inactiveComputers) { Remove-ADComputer -Identity $computer.Name }
Opens a dialog box asking to confirm to delete objects. Will not work as I require it to run with no user interaction.
2)
foreach ($computer in $inactiveComputers) { Remove-ADComputer -Identity $computer.Name -Confirm:$false }
Error Caught:
The directory service can perform the requested operation only on a leaf object
3)
foreach ($computer in $inactiveComputers) { Get-ADComputer $computer.Name | Remove-ADObject -Recursive }
Opens a dialog box asking to confirm to delete objects. Will not work as I require it to run with no user interaction.
4)
foreach ($computer in $inactiveComputers) { Get-ADComputer $computer.Name | Remove-ADObject -Recursive -Confirm:$False }
Error Caught:
Access is Denied
5)
Reopened PowerShell ISE as an administrator and ran the same set of commands again
Error Caught:
Access is Denied
Note:
The computer objects are NOT protected by accidental deletion.
Some thoughts on how to accomplish this would be great.
Colin Domansky