Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mrik23/f7add4fcc82f89250b7c6bd73f5d0a52 to your computer and use it in GitHub Desktop.
Save mrik23/f7add4fcc82f89250b7c6bd73f5d0a52 to your computer and use it in GitHub Desktop.
PowerShell script for Active Directory. In "one" line script we are able to retrieve users based on a specific attribute and update some attributes to them.
<#
This is an example on how to filter out users based on some standard filter and non-standard attribute.
In this case we pull all active users with the company Contoso, we force the attribute countryCode to be retrieved.
Then we select the users that have the countryCode empty and finally set the correct attributes for these users.
#>
$Users = Get-ADUser -Filter 'enabled -eq $true -and company -eq "Contoso"'`
-SearchBase "OU=Texas,DC=Contoso,DC=com"`
-Properties Department, Title, countryCode | `
where {$_.countryCode -eq ""} | `
Set-ADUser -Replace @{c="US";co="United States";countrycode=840}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment