Skip to content

Instantly share code, notes, and snippets.

@sballarati
Created February 3, 2016 20:48
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 sballarati/b078e956f3c07464c001 to your computer and use it in GitHub Desktop.
Save sballarati/b078e956f3c07464c001 to your computer and use it in GitHub Desktop.
Creates an Azure Active Directory Service Principal
#connect using a global admin account of the AD where you want the Service Principal to be created
$msolcred = get-credential
connect-msolservice -credential $msolcred
#symmetric key used for some auth scenarios (keep the object id, app principal id and symm key for the future)
New-MsolServicePrincipal -DisplayName {yourspname} -Type symmetric
#assigns a Company Admin role
Add-MsolRoleMember -RoleName "Company Administrator" -RoleMemberType ServicePrincipal -RoleMemberObjectId {principal objectId}
#the password credential will be valid for 1 year, you can also set another value
New-MsolServicePrincipalCredential -AppPrincipalId {principalId} -Type Password -StartDate ([DateTime]::Now.AddMinutes(-5)) -EndDate ([DateTime]::Now.AddMonths(12)) -Value "{yourpass}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment