Skip to content

Instantly share code, notes, and snippets.

@krohrbaugh
Created October 7, 2013 22:01
Show Gist options
  • Save krohrbaugh/6875688 to your computer and use it in GitHub Desktop.
Save krohrbaugh/6875688 to your computer and use it in GitHub Desktop.
Windows Azure Active Directory: Add role to service principal
# Using the Windows Azure Active Directory Module for Windows PowerShell
#
# Connect to the tenant to modify
Connect-MsolService # => login
# Get Service Principal to add the role to
$servicePrincipal = Get-MsolServicePrincipal -ServicePrincipalName Principal.Name
# Get role object ID
# Alternatively, you can list all the roles (in order to get a different role name) using just `Get-MsolRole`
$roleId = (Get-MsolRole -RoleName "Directory Readers").ObjectId
# Add role to service principal
Add-MsolRoleMember -RoleObjectId $roleId -RoleMemberObjectId $servicePrincipal.ObjectId -RoleMemberType servicePrincipal
# Check our work
Get-MsolRoleMember -RoleObjectId $roleId # => should include Principal.Name in list
@Gang-Peng
Copy link

like

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment