title: PowerShell script to exclude a list of computers from getting disabled in AD
body: <p>Could you guys please help me with the following scenario . Here is what i am trying to accomplish . </p>
  
  <ol>
  <li><p>I generate a report of computers that need that need to be disabled in AD = file1.txt</p></li>
  <li><p>I have a pre-made list of Computers to exclude
  from getting disabled = file2.txt </p></li>
  <li>I have a script to disable a list
  of computers from a text file but i would like to exclude whatever
  computer that exist in the file2.txt .</li>
  </ol>
  
  <p>Here is what i have so far </p>
  
  <pre><code>$toBeDisabled = Import-CSV \\SERVER\file1.csv
  </code></pre>
  
  <p>$toBeExcluded  = Import-CSV \SERVER\file2.csv</p>
  
  <p>$toBeDisabled = $toBeExcluded | Where-Object {($toBeExcluded | Select-Object -ExpandProperty Name) -NotContains $_.Name}</p>
  
  <p>ForEach ($Computer in $toBeDisabled.DeviceName)</p>
  
  <p>{ 
      $Computer = $Computer.Trim()</p>
  
  <pre><code>$ADComputer = Get-ADComputer $Computer -Properties Description
  </code></pre>
  
  <p>If ($ADComputer)</p>
  
  <p>{ 
  Add-Content c:\temp\computers.log -Value "The following PC $Computer has been found and disabled"</p>
  
  <p>Set-ADComputer $ADComputer -Description "$($ADComputer.Description)- Disable due to inactivity - $(Get-Date) - by $env:UserName " -Enabled $False</p>
  
  <p>}</p>
  
  <p>Else</p>
  
  <p>{ Add-Content c:\temp\computers.log -Value "$Computer not Found in Active Directory or Was disabled before"</p>
  
  <p>}</p>
  
  <p>} </p>
  
  <p>Im getting the following error (Select-Object : Property "Name" cannot be found)</p>
  
  <p>Thanks </p>