Skip to content

Instantly share code, notes, and snippets.

@IT-Delinquent
Last active November 3, 2022 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IT-Delinquent/09c7fef62d8a49a37dcb5afe5592bfb7 to your computer and use it in GitHub Desktop.
Save IT-Delinquent/09c7fef62d8a49a37dcb5afe5592bfb7 to your computer and use it in GitHub Desktop.
cleanGetAndUpdateAzureADAttribute
#51 River St., Ridgefield, CT 06877
#New props in a hashtable for splatting
$newProps = @{
StreetAddress = '51 River St.'
City = 'Ridgefield'
State = 'CT'
PostalCode = '06877'
Country = 'United States'
}
#Get all marketing users
$marketingUsers = $null
try {
$marketingUsers = Get-AzureADUser -ErrorAction Stop | `
Where-Object {$_.Department -eq 'Marketing'}
}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;
}
#Running through each user
foreach ($user in $marketingUsers){
try{
Set-AzureADUser -ObjectId $user $newProps -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