Determine domain of the computer

Welcome Forums General PowerShell Q&A Determine domain of the computer

  • This topic has 2 replies, 2 voices, and was last updated 8 months ago by
    Participant
    .
Viewing 2 reply threads
  • Author
    Posts
    • #211938
      Participant
      Topics: 12
      Replies: 21
      Points: 135
      Rank: Participant

      I am looking for an output from the computerlist to determine if that computer exist in AD, but along with that I also need to pull out the Domain and the ping result.

      Domain =$domain – This gives me a wrong result and not sure where to put in this. I am missing something simple, but not able to resolve it

    • #211977
      Participant
      Topics: 17
      Replies: 1872
      Points: 3,640
      Helping Hand
      Rank: Community Hero

      The domain is contained in the DistinguishedName, but try changing you loop a bit like this and see if it works (untested):

    • #216315
      Participant
      Topics: 12
      Replies: 21
      Points: 135
      Rank: Participant

      The domain is contained in the DistinguishedName, but try changing you loop a bit like this and see if it works (untested):

      PowerShell
      23 lines

      <textarea class=”ace_text-input” wrap=”off” autocorrect=”off” autocapitalize=”off” spellcheck=”false” style=”opacity: 0; height: 18px; width: 7px; left: 51px; top: 0px;”></textarea>

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      $Domains = “Domain1′, “Domain2
      $Computers= get-content “C:\temp\Computers.txt”
      $results = foreach ($computer in $Computers){
      foreach ($domain in $Domains){
      $computer = Get-ADComputer Filter {SamAccountName -eq $computer} Server $domain |
      Select @{Name=‘DN’;Expression={$_.DistinguishedName}},
      Name,
      @{Name=‘Domain’;Expression={$domain}}
      }
      if (!$computer) {
      [PSCustomObject]@{
      Name = $computer
      DN = $null
      Domain = $null
      }
      }
      }
      $results
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

      Sorry for the late reply on this. thanks for your guidancce

Viewing 2 reply threads
  • The topic ‘Determine domain of the computer’ is closed to new replies.