PowerShell Add to Global Admin
Today I was working on adding all the new admin accounts we made for a client to the Global Admin Role for Microsoft 365 as part of the onboarding process. Prior I had added the accounts in the local AD accounts using PowerShell and set them to sync with AD Connect. We have a lot of admin accounts we are making and adding them one-by-one via GUI was not something I wanted to do anymore.
#I opened up PowerShell ISE on my local computer
#Connected to MS 365 for this client using a Global Admin account
Connect-AzureAD
#There are 2 variabled I needed for this command. The first is the ObjectID of the Global Admin group
Get-AzureADDirectoryRole | Where DisplayName -like "GL*" | Select DisplayName, ObjectID
#copy out the Object ID
#The second is the ID of the user accounts you want. I used this command to narrow it down to just the names I was looking for
Get-AzureADUser | Where DisplayName -like "Admin*" | FT DisplayName, objectID
#the ObjectID for the user is the RefObjectID in the below commands
#The ObjectID of the role is the first ID. The second is the user ID.
Add-AzureADDirectoryRoleMember -ObjectId 2391f956-f330-4f76-854a-e57687457f54 -RefObjectId c354800b-db6b-46c3-a704-0f03da294b5b
Add-AzureADDirectoryRoleMember -ObjectId 2391f956-f330-4f76-854a-e57687457f54 -RefObjectId 3b9e26a9-b46c-43fb-8ed0-e9634f572f82
No Comments