All Projects → baswijdenes → Optimized.Mga

baswijdenes / Optimized.Mga

Licence: other
PowerShell module for Microsoft Graph REST API. To optimize, speed, and bulk use Microsoft Graph API in PowerShell. You can can enter your own URL so you aren't restricted to the limitations of the official Microsoft Module. Includes ways to speed up the process, handle throttling, and re-authenticate after the token expires.

Programming Languages

powershell
5483 projects

Projects that are alternatives of or similar to Optimized.Mga

AzureGraph
R interface to Microsoft Graph REST API
Stars: ✭ 28 (-3.45%)
Mutual labels:  microsoft-graph-api
tod0
A Terminal Client for Microsoft To-Do
Stars: ✭ 93 (+220.69%)
Mutual labels:  microsoft-graph-api
microsoft-he4rt
A 2 day challenge to develop any project using Microsoft Graph and Azure
Stars: ✭ 15 (-48.28%)
Mutual labels:  microsoft-graph-api
BlazorGraphApi
Blazor Server App with Azure AD Authentication, that calls the Microsoft Graph API on-behalf of the signed-in user.
Stars: ✭ 28 (-3.45%)
Mutual labels:  microsoft-graph-api
powershell
PnP PowerShell
Stars: ✭ 326 (+1024.14%)
Mutual labels:  microsoft-graph-api
active-directory-dotnet-graphapi-b2bportal-web
Demonstration/prototype of B2B self-service signup, signup approvals, and profile editing.
Stars: ✭ 64 (+120.69%)
Mutual labels:  microsoft-graph-api
QuickTeams
Download, Clone, Archive, Un-Archive your Microsoft Teams and manage the apps you've installed to them
Stars: ✭ 31 (+6.9%)
Mutual labels:  microsoft-graph-api
ms-identity-mobile-apple-swift-objc
An iOS sample in Swift that authenticates Microsoft Account and Azure AD users and calls the Graph API using OAuth 2.0
Stars: ✭ 61 (+110.34%)
Mutual labels:  microsoft-graph-api

Optimized.Mga

PowerShell Gallery PowerShell Gallery

Don't you wish you have a Microsoft Graph module which handles batching, the token and throttling for you, but where you can just enter your own URL, so you aren't restricted to the limitations of the official Microsoft Module and even includes a way to speed up the process?


CHANGELOG


Submodules dependent on Optimized.Mga:


Optimized.Mga Cmdlets


Are you new with the Microsoft Graph API?


What makes your module different from the official Microsoft Graph SDK for PowerShell?


Speed

The main difference is speed.

Group-Mga doesn't lie. When I use Measure-Command while creating 10,000 users via the Post command it takes about 41 minutes:

$CreatedUsers.count
10000
Measure-Command {
    foreach ($User in $CreatedUsers) {
        try {
            New-Mga -URL 'https://graph.microsoft.com/v1.0/users' -Body $User
        }
        catch {
            continue
        }
    }
}

Minutes           : 41
Seconds           : 6
Milliseconds      : 717

When I create the same users via Group-Mga, it's 10 minutes:

$Batch = [System.Collections.Generic.List[Object]]::new()
foreach ($User in $CreatedUsers) {
    $Object = [PSCustomObject]@{
        Url    = "/users"
        method = 'post'
        body   = $User
    }
    $Batch.Add($Object)
}
Measure-Command {
    Group-Mga -Body $Batch
}

Minutes           : 9
Seconds           : 43
Milliseconds      : 152

Group-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.

Usability

The second difference is usability. If you look at the official module you will see 33 dependencies. I made my module so that you only need 8 cmdlets.

The main cmdlet is of course Group-Mga, by using Fiddler, or the browser developer tools you can find the URL when navigating through AzureAD and use it in one of the cmdlets.

For example the below URL is from the Intune Management GUI and found with Fiddler. It will get the Windows compliant devices and will only select the ComplianceState and UserPrincipalname.

$URL = 'https://graph.microsoft.com/beta/deviceManagement/managedDevices?$filter={0}&$top=999&$select=userPrincipalName,complianceState' -f "complianceState%20eq%20'Compliant'%20and%20operatingSystem%20eq%20'Windows'"
Get-Mga -URL $URL

Bulk

Set-Mga with parameters -Body and -Batch and with the Property [email protected] will automatically be batched. So, in theory you can add 10000 users to a Group instantly. While throttling is handled for you.

$CreatedUsers = Get-Mga -URL 'https://graph.microsoft.com/v1.0/users?$top=999'
$UserPostList = [System.Collections.Generic.List[Object]]::new() 
foreach ($User in $CreatedUsers)
{
    $DirectoryObject = 'https://graph.microsoft.com/v1.0/directoryObjects/{0}' -f $User.id
    $UserPostList.Add($DirectoryObject)
}
$PostBody = [PSCustomObject] @{
    "[email protected]" = $UserPostList
}

Set-Mga -URL 'https://graph.microsoft.com/v1.0/groups/ac252320-4194-402f-8182-2d14e4a2db5c' -Body $PostBody -Verbose

Same goes for Remove-Mga. When parameter -URL is an Array, it will automatically batch your request:

$Groupusers = Get-Mga -URL 'https://graph.microsoft.com/v1.0/groups/ac252320-4194-402f-8182-2d14e4a2db5c/members'
$UserList = @()
foreach ($User in $Groupusers) {
    $URL = 'https://graph.microsoft.com/v1.0/groups/ac252320-4194-402f-8182-2d14e4a2db5c/members/{0}/$ref' -f $User.Id
    $UserList += $URL
}
Remove-Mga -URL $UserList
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].