Skip to content

Instantly share code, notes, and snippets.

@irwinwilliams
Created October 7, 2016 12:50
Show Gist options
  • 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