Microsoft.Graph.API: Cmdlets for version 0.1.9


The module prefix changed from MSGraph to Mga to shorten the cmdlets as much as possible.

Removed cmdlets in version 0.1.9

Removed from module:

  • New-MSGraphPreGetRequest

Renamed Cmdlets in version 0.1.9

  • Connect-MSGraph -> Connect-Mga
  • Disconnect-MSGraph -> Disconnect-Mga
  • New-MSGraphGetRequest > Get-Mga
  • New-MsGraphPostRequest > Post-Mga
  • New-MSGraphPatchRequest > Patch-Mga
  • New-MSGraphDeleteRequest > Delete-Mga

New cmdlets in version 0.1.9

  • Batch-Mga
  • Send-MgaMail

Update Cmdlets in version 0.1.9


By selecting one of these parameters you log on with the following:

  • ClientSecret: Will log you on with a ClientSecret.
  • Thumbprint: Will log you on with a Certificate.
  • UserCredentials: Will log you on with basic authentication.
  • RedirectUri: Will log you on with MFA Authentication.

The OauthToken is automatically renewed when you use cmdlets.

If you want to know more about how to log in via MFA with a RedirectUri, follow this link.



Connect-Mga -Thumbprint '3A7328F1059E9802FAXXXXXXXXXXXXXX' -applicationID 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX' -Tenant '' 


Connect-Mga -redirectUri 'msalXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX://auth' -Tenant ''  -ApplicationID 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX'


To update the OauthToken I fill the global scope with a number of properties. The properties are emptied by Disconnect-Mga.




Get-Mga speaks for itself. All you have to provide is the URL.

You can grab the URL via the browser developer tools, Fiddler, or from the Microsoft Graph docs. You can use all query parameters in the URL like some in the examples.

It will automatically use the Next Link when there is one in the returned request.

If you only want to retrieve data once, you can use the -Once parameter. For example, I used this in the beta version to get the latest login. Nowadays this property is with the user under signInActivity.


Get-Mga -URL '' -Once

Get-Mga -URL '$top=999'

$URL = '$select={0}' -f 'id,userPrincipalName,lastPasswordChangeDateTime,createdDateTime,PasswordPolicies' 
Get-Mga -URL $URL

$URL = '$filter=({0})&$select=displayName,userPrincipalName,createdDateTime,signInActivity' -f "UserType eq 'Guest'"
Get-Mga URL $URL


Post-Mga can be seen as the ‘new’ Verb. With this cmdlet you create objects in AzureAD.

-InputObject will accept a PSObject or JSON.

The example below creates a new user.


$InputObject = @{
    accountEnabled    = 'true'
    displayName       = "Test User Post MSGraph"
    mailNickname      = "TestUserPostMSGraph"
    userPrincipalName = "[email protected]"
    passwordProfile   = @{
        forceChangePasswordNextSignIn = 'true'
        password                      = 'XXXXXXXXXX'
Post-Mga -URL '' -InputObject $InputObject


Patch-Mga can be seen as the ‘Update’ Verb.

-InputObject will accept a PSObject or JSON.

InputObject with [email protected] property over 20+ users will automatically be batched.

In the below example I add users to a Group.


$users = Get-Mga ''
$UserPostList = [System.Collections.Generic.List[Object]]::new() 
foreach ($User in $users)
    $DirectoryObject = '{0}' -f $
$PostBody = [PSCustomObject] @{
    "[email protected]" = $UserPostList
Patch-Mga -URL '' -InputObject $PostBody 


Delete speaks for itself. With this cmdlet you can remove objects from AzureAD.

-URL accepts an array of URLS, it will use Batch-Mga in the backend.

-InputObject will accept a PSObject or JSON.


Delete-Mga -URL '[email protected]' 


Batch-Mga is espcially for speed and bulk.

Go to Speed or Bulk for more.

Batch-Mga will take care of the limitations(20 requests per batch) and will sleep for the amount of time a throttle limit is returned and then continue.


$DeletedObjects = Get-Mga -URL '$top=999'
$Batch = [System.Collections.Generic.List[Object]]::new()
foreach ($User in $DeletedObjects) {
    $Object = [PSCustomObject]@{
        url    = "/directory/deletedItems/$($"
        method = 'delete'
Batch-Mga -InputObject $batch


Send-MgaMail speaks for itself.

The -From addres can only be used when you connect with an App Registration.


Send-MgaMail -From '[email protected]' -To '[email protected]' -Subject 'Test message' -Body 'This is a test message'

Send-MgaMail -To '[email protected]' -Subject 'Test message' -Body 'This is a test message'

Previous version

Version 0.1.8