title: Powershell duplicating data output
body: <p>I copied the PowerShell code from <a href="https://gallery.technet.microsoft.com/scriptcenter/List-of-Users-from-Remote-66def6c2" rel="nofollow noreferrer">this</a> site that displays the local user accounts for the computers that I want to search in my domain.</p>
  <p>I edited it a bit to the following to show <strong>NOT_FOUND</strong> if that PC is turned off or just can't find it:</p>
  <pre><code>Param
  (
      [Parameter(Position=0,Mandatory=$false)]
      [ValidateNotNullorEmpty()]
      [Alias('cn')][String[]]$ComputerName=$Env:COMPUTERNAME,
      [Parameter(Position=1,Mandatory=$false)]
      [Alias('un')][String[]]$AccountName,
      [Parameter(Position=2,Mandatory=$false)]
      [Alias('cred')][System.Management.Automation.PsCredential]$Credential
  )
      
  $Obj = @()
  
  Foreach($Computer in $ComputerName)
  {
  
      If($Credential)
      {
          $AllLocalAccounts = Get-WmiObject -Class Win32_UserAccount -Namespace &quot;root\cimv2&quot; `
          -Filter &quot;LocalAccount='$True'&quot; -ComputerName $Computer -Credential $Credential -ErrorAction SilentlyContinue
      }
      else
      {
          
          $AllLocalAccounts = Get-WmiObject -Class Win32_UserAccount -Namespace &quot;root\cimv2&quot; `
          -Filter &quot;LocalAccount='$True'&quot; -ComputerName $Computer  -ErrorAction SilentlyContinue -ErrorVariable NotFound
      }
  
      If ($NotFound) {
          
          $Object = New-Object -TypeName PSObject
  
          $Object|Add-Member -MemberType NoteProperty -Name &quot;Name&quot; -Value &quot;NOT_FOUND&quot;
          $Object|Add-Member -MemberType NoteProperty -Name &quot;Disabled&quot; -Value &quot;TRUE&quot;
          $Object|Add-Member -MemberType NoteProperty -Name &quot;Domain&quot; -Value $Computer
          $Obj+=$Object
          $NotFound = $null
      }
      else{
          Foreach($LocalAccount in $AllLocalAccounts)
          {
              $Object = New-Object -TypeName PSObject
          
              $Object|Add-Member -MemberType NoteProperty -Name &quot;Name&quot; -Value $LocalAccount.Name
              $Object|Add-Member -MemberType NoteProperty -Name &quot;Disabled&quot; -Value $LocalAccount.Disabled
              $Object|Add-Member -MemberType NoteProperty -Name &quot;Domain&quot; -Value $LocalAccount.Domain
              $Obj+=$Object
          }
      }
      If($AccountName)
      {
          Foreach($Account in $AccountName)
          {
              $Obj|Where-Object{$_.Name -like &quot;$Account&quot;}
          }
      }
      else
      {
          $Obj
      }
  }
  </code></pre>
  <p>I enter the following:</p>
  <pre><code>.\GetLocalAccount.ps1  -Computername &quot;Comp1&quot;, &quot;Comp2&quot;, &quot;Comp3&quot;, &quot;Comp4&quot;
  </code></pre>
  <p>The problem is that the output seems to be duplicating. I've tried debugging in ISE and don't see this in the $obj variable.</p>
  <p>My Output is the following:</p>
  <pre><code>Name               Disabled Domain      
  ----               -------- ------      
  Administrator         False Comp1
  DefaultAccount         True Comp1
  Guest                  True Comp1
  WDAGUtilityAccount     True Comp1
  Administrator         False Comp1
  DefaultAccount         True Comp1
  Guest                  True Comp1
  WDAGUtilityAccount     True Comp1
  NOT_FOUND              TRUE Comp2
  Administrator         False Comp1
  DefaultAccount         True Comp1
  Guest                  True Comp1
  WDAGUtilityAccount     True Comp1
  NOT_FOUND              TRUE Comp2
  NOT_FOUND              TRUE Comp3   
  Administrator         False Comp1
  DefaultAccount         True Comp1
  Guest                  True Comp1
  WDAGUtilityAccount     True Comp1
  NOT_FOUND              TRUE Comp2
  NOT_FOUND              TRUE Comp3   
  Administrator         False Comp4
  DefaultAccount         True Comp4
  Guest                  True Comp4
  WDAGUtilityAccount     True Comp4
  </code></pre>
  <p>The Output should be:</p>
  <pre><code>Name               Disabled Domain      
  ----               -------- ------      
  Administrator         False Comp1
  DefaultAccount         True Comp1
  Guest                  True Comp1
  WDAGUtilityAccount     True Comp1
  NOT_FOUND              TRUE Comp2
  NOT_FOUND              TRUE Comp3   
  Administrator         False Comp4
  DefaultAccount         True Comp4
  Guest                  True Comp4
  WDAGUtilityAccount     True Comp4
  </code></pre>