# Get & Remove AD Computer Error

**URL:** <https://forums.powershell.org/t/get-remove-ad-computer-error/9716>\
**Category:** PowerShell Help\
**Created:** [November 15, 2017, 4:27pm UTC](https://forums.powershell.org/t/get-remove-ad-computer-error/9716 "2017-11-15T16:27:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgcovalt](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jgcovalt](https://forums.powershell.org/u/jgcovalt)\
**Post date:** [November 15, 2017, 4:27pm UTC](https://forums.powershell.org/t/get-remove-ad-computer-error/9716/1 "2017-11-15T16:27:02Z")

</div>

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"."

---

<div class="post-metadata">

**Author:** ![jgcovalt](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jgcovalt](https://forums.powershell.org/u/jgcovalt)\
**Post date:** [November 15, 2017, 4:43pm UTC](https://forums.powershell.org/t/get-remove-ad-computer-error/9716/2 "2017-11-15T16:43:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [November 15, 2017, 6:58pm UTC](https://forums.powershell.org/t/get-remove-ad-computer-error/9716/3 "2017-11-15T18:58:13Z")

</div>

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 }

---

<div class="post-metadata">

**Author:** ![jgcovalt](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jgcovalt](https://forums.powershell.org/u/jgcovalt)\
**Post date:** [November 16, 2017, 8:24am UTC](https://forums.powershell.org/t/get-remove-ad-computer-error/9716/4 "2017-11-16T08:24:35Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:37pm UTC](https://forums.powershell.org/t/get-remove-ad-computer-error/9716/5 "2024-05-16T20:37:12Z")

</div>

Closed on May 16, 2024, 8:37pm UTC


