Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#Get all marketing users
$marketingUsers = $null
try {
$marketingUsers = Get-AzureADUser -Filter "Department eq 'Marketing'" -ErrorAction Stop
#Output the error message if any
Write-Host "Failed to collect Marketing users!" -ForegroundColor Red
Write-Host $_.ScriptStackTrace -ForegroundColor Red
#Checking if there are no marketing users found
if (!$marketingUsers){
Write-Host "No Marketing users found"
#Run through each user and update
foreach($user in $marketingUsers){
Set-AzureADUser -ObjectID $user `
-StreetAddress '51 River St.' `
-City 'Ridgefield' `
-State 'CT' `
-PostalCode '06877' `
-Country 'United States' `
-ErrorAction Stop
Write-Host "Failed to update $user" -ForegroundColor Red
Write-Host $_.ScriptStackTrace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment