Last active
November 3, 2022 14:15
-
-
Save IT-Delinquent/90973cbf9d99f471dc8027babb98d709 to your computer and use it in GitHub Desktop.
lessDirtyGetAndUpdateAzureADAttributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Get all marketing users | |
$marketingUsers = $null | |
try { | |
$marketingUsers = Get-AzureADUser -Filter "Department eq 'Marketing'" -ErrorAction Stop | |
}catch{ | |
#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" | |
return; | |
} | |
#Run through each user and update | |
foreach($user in $marketingUsers){ | |
try{ | |
Set-AzureADUser -ObjectID $user ` | |
-StreetAddress '51 River St.' ` | |
-City 'Ridgefield' ` | |
-State 'CT' ` | |
-PostalCode '06877' ` | |
-Country 'United States' ` | |
-ErrorAction Stop | |
}catch{ | |
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