In my ninth article In the series on Active Directory PowerShell Module shows how to manage Active Directory using PowerShell I’m going to explore the usage of the Get-ADComputer and Set-ADComputer cmdlet and will show you how mange single and multiple computers.
The most basic cmdlet In the module will show you how to get a list of all the computer In the domain using PowerShell.
Get-ADComputer -Filter * | ft
You can also Import users from a CSV file and get Info about them:
Import-Csv .\computers.csv | foreach{ New-ADComputer $_.pc -PassThru}
To create multiple computers In a specific OU use:
Import-Csv .\computers.csv | foreach{ New-ADComputer $_.pc -Path "ou=dev,dc=test,dc=local" -PassThru}
To delete multiple computer from a CSV file use:
Import-Csv .\computers.csv | foreach{ remove-ADComputer $_.pc -Verbose -Confirm:$false}
To set Value to multiple computers use:
Import-Csv .\computers.csv | foreach{ set-ADComputer $_.pc -Location "West Data Center" -PassThru }
Import-Csv .\computers.csv | foreach{ set-ADComputer $_.pc -ManagedBy "David" -PassThru }
Import-Csv .\computers.csv | foreach{ set-ADComputer $_.pc -AccountExpirationDate "09/09/2019" -PassThru }
To change the description of multiple computer from a CSV file use:
Import-Csv .\computers.csv | foreach { Set-ADComputer $_.pc -add @{description="South DC"} -PassThru }
To reset values (set to null) use:
#Import-Csv .\computers.csv | foreach { Set-ADComputer $_.pc -Description $null -PassThru }
Don’t forget to read the previous article In the series Search For Locked Users And Expired Users Using Active Directory PowerShell