Author Posts

November 15, 2017 at 9:57 pm

So, I'm using the Get-ADComputer cmdlet to retrieve computers from a list of computer names, then attempting to use Remove-ADComputer to delete these, as they should no longer be in our AD.

When I do so, I get the error below. Anyone know why this doesn't work, as Get-ADComputer should return an ADComputer object?

Remove-ADComputer : Cannot bind parameter 'Identity'. Cannot convert value "" to type "Microsoft.ActiveDirectory.Management.ADComputer". Error: "Cannot convert the "" value of
type "Deserialized.Microsoft.ActiveDirectory.Management.ADComputer" to type "Microsoft.ActiveDirectory.Management.ADComputer"."

November 15, 2017 at 10:13 pm

And then I figured it out; I had to convert the ADComputer to a string. Not sure why the documentation says it needs to be an ADComputer for Remove-ADComputer, when it's looking for the string that is the FQDN instead.

November 16, 2017 at 12:28 am

Glad you gleaned your onw error.

However, the PoSH online help is pretty specific about how / why to use cmdlet x.

Get-Help -Name Get-ADComputer -Examples

You say ...
'Get-ADComputer cmdlet to retrieve computers from a list of computer names'
... where is this list?

If it is a text file, then you cannot use GetADComputer against a text file. You have to read in that text file, and pipe that to Get-ADComputer and pipe that to Remove-ADComputer.

(Get-Content -Path 'C:\temp\ComputersToremoveFromAD.txt') |
% { Get-ADComputer $_ |
Remove-ADComputer -Identity $_.Name -WhatIf }

If you are just typing them in say, inline...

'computer1','computer2','computer3' |
% { Get-ADComputer $_ |
Remove-ADComputer -Identity $_.Name -WhatIf }

November 16, 2017 at 1:54 pm

I pulled the names from a csv file that contains several pieces of information I needed for different parts of the script. To get the name, I just used a ForEach, and grabbed the name from the data ($Comps.ComputerName).