top of page

PowerShell Set-ADComputer

#============================================================================================
# I Suggest doing a full backup of all the changes you plan to update or change.
# Use the Snippet Below to pull any Info you are about to Update in AD and Export to CSV
# Review output then proceed with the next part of the scrpt to update the description field.
# Please note this does not append this will overwrite the current description if any. 
#============================================================================================

#Get Computer Input From CSV File, Columns Server,Owner
$Computer_input = Import-csv 'C:\temp\Computer Descript Update\Comp_Update-Test.csv'

#Da Loop
Foreach($Comp in $Computer_input){

    Try{
         
#Always Backup Current Data In AD Before Replacing or Updating Field/s 
          Get-ADComputer $Comp.Server -Properties * -ErrorAction Continue | Select Name, Description   | Export-csv C:\temp\Old_Descrption-Files.csv -Append -NoTypeInformation
        }Catch{            
         
#If Computer Name Not Found in AD Export to File 
          $Comp | Select -ExpandProperty Server | Out-File C:\temp\Not-Found-in-AD.txt -Append}

}

#=====================================================================================================
# Part 2

# Note: I suggest doing a test group first and review results. 
#=====================================================================================================

#Get Computer Input From CSV File, Columns Server,Owner

$Computer_input = Import-csv 'C:\temp\Computer Descript Update\Comp_Update-Test.csv'

#Da Loop
Foreach($Comp1 in $Computer_input){

    Try{
         
  #Update Computer Description Field with System Owner
            Set-ADComputer -Identity $Comp1.Server -ErrorAction Continue -Description $Comp1.Owner
                  
        }Catch{            
           
#If Fails Export to File 
            $Comp | Select -ExpandProperty Server | Out-File C:\temp\Update-Error.txt -Append
        }
}

#Da Loop
Foreach($Comp2 in $Computer_input){
   
#Loop Back Through to Check on Update.  
    Get-ADComputer $Comp2.Server -Properties * -ErrorAction Continue | Select Name, Description
}

bottom of page