Powershell script to add/apend AD computer description

Pratik Virani 1 Reputation point
2022-11-30T12:28:03.433+00:00

We require to add description having server owner name in overall infra and need to append with server owner name where existing data is already there. Is there any quick way which I know it could be to be done in one go.

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2022-11-30T20:05:23.503+00:00

    You don't say how you'll get the information!

    Is there a reason you're using the "Description" property instead of the "ManagedBy" property to identify the person responsible for the computer?

    Here's one way to do what you asked:

    #  
    # CSV file has two columns: "Computer" and "Owner"  
    #  
      
    Import-CSV c:\junk\ComputerOwner.csv|  
        ForEach-Object{  
            $c = Get-ADComputer -Filter "Name -eq '$_.Computer'" -Properties Description  
            if ($c){  
                $c | Set-Computer -Description ("{0} {1}" -f $c.Description, $_.Owner)  
            }  
            else{  
                Write-Host "Computer '$($_.Computer)' was not found." -ForegroundColor Yellow  
            }  
        }  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.