Get & Remove AD Computer Error

This topic contains 3 replies, has 2 voices, and was last updated by  Jon Covalt 7 months, 1 week ago.

  • Author
  • #84335

    Jon Covalt

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

  • #84337

    Jon Covalt

    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.

  • #84355


    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 }

    • #84371

      Jon Covalt

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

You must be logged in to reply to this topic.