Skip to content

Instantly share code, notes, and snippets.

@irwinwilliams
Created October 7, 2016 12:50
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 irwinwilliams/b14d4b5dd972dff4e4342f110b35771b to your computer and use it in GitHub Desktop.
Save irwinwilliams/b14d4b5dd972dff4e4342f110b35771b to your computer and use it in GitHub Desktop.
Set Roles in Azure AD via PowerShell
#'I got this from here: https://github.com/Azure-Samples/active-directory-dotnet-graphapi-console/issues/27#issuecomment-155565140
$Tenant = "[something].onmicrosoft.com";
$tenantGuid = "[find this in the manifest]"
$graphver = "1.5"
$appID = "[also manifest, but portal, too.]"
$userVal = "[username]@" + $tenant
$pass = "[password]"
$creds = New-Object System.Management.Automation.PsCredential($userVal, (ConvertTo-SecureString $pass -AsPlainText -Force))
Connect-MsolService -Credential $creds
$msSP = Get-MsolServicePrincipal -AppPrincipalId $appID -TenantID $tenantGuid
#ID of the Application
$objectId = $msSP.ObjectId
$roleName = "Company Administrator"
Add-MsolRoleMember -RoleName $roleName -RoleMemberType ServicePrincipal -RoleMemberObjectId $objectId
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment