Automate the removal of the DNS Root of a computer name

This topic contains 2 replies, has 2 voices, and was last updated by  I Am Sir Ask Alot 1 year, 12 months ago.

  • Author
  • #44373

    I Am Sir Ask Alot

    I am trying to figure out how I can remove the DNS Root of a computer so I can plug that into the Get-ADComputer cmdlet.

    What I am doing is taking a list of IP addresses and resolving those to computer names like so:

    $ComputerNames = @(Get-Content 'C:\IPAddressList.txt' | ForEach-Object{ 

    Then when I call on the $ComputerNames variable it gives me the computer names along with the DNS Root at the end, like so:

    How can I go about removing the "" DNS Root so I can just use the computer name for Get-ADComputer?

    Get-ADComputer errors if I try to use ''


  • #44393

    Don Jones

    Assuming $computername has the entire string,

    $justthecomputer = $computername -replace "",""

    Would do that.

  • #45062

    I Am Sir Ask Alot

    Thanks Don, I already figured this out by doing the following:

    $FQDNComputers = ''
    $DNSRoot = (Get-ADDomain).DNSRoot 
    Foreach ($Computer in $FQDNComputers)
        $Computer -Replace(".$DNSRoot","")

You must be logged in to reply to this topic.