Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# This script will try to create 251 groups
# The last one should fail
# configuration:
# 1. create an account nonadmin@takana16.onmicrosoft.com
# 2. go to https://developer.microsoft.com/en-us/graph/graph-explorer, make a call and grab the access token
$token = "eyJ0eXAiOiJKV1QiLCJub25jZSI6Iko1WXU2MWRtR3FsR0JaaVJ0YTJsM0duUFdBLW5FY19yWk90aFNFNlg3MUEiLCJhbGciOiJSUzI1NiIsIng1dCI6ImFQY3R3X29kdlJPb0VOZzNWb09sSWgydGlFcyIsImtpZCI6ImFQY3R3X29kdlJPb0VOZzNWb09sSWgydGlFcyJ9.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTAwMDAtYzAwMC0wMDAwMDAwMDAwMDAiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC8wMzRmOGFhOC01NTBiLTRjZmEtODZhNi03NWFkNTdmMTNkNDkvIiwiaWF0IjoxNTcxOTk3NzQ5LCJuYmYiOjE1NzE5OTc3NDksImV4cCI6MTU3MjAwMTY0OSwiYWNjdCI6MCwiYWNyIjoiMSIsImFpbyI6IkFTUUEyLzhOQUFBQWFmNDJjVjFMTUdZRzlmMFh4TDNCK0pLbTdrR2NNQ3FLcHI3TUtFVlNwdUU9IiwiYW1yIjpbInB3ZCJdLCJhcHBfZGlzcGxheW5hbWUiOiJHcmFwaCBleHBsb3JlciIsImFwcGlkIjoiZGU4YmM4YjUtZDlmOS00OGIxLWE4YWQtYjc0OGRhNzI1MDY0IiwiYXBwaWRhY3IiOiIwIiwiZmFtaWx5X25hbWUiOiJNaXJvbm92IiwiZ2l2ZW5fbmFtZSI6IkFuYXRvbHkiLCJpcGFkZHIiOiIyMTIuNzMuMTY0LjExIiwibmFtZSI6IkFuYXRvbHkgTWlyb25vdiIsIm9pZCI6IjI5OGU2MjNmLTg1M2MtNDcxYS1hODhkLWJkZjA3OTcxNzg5NSIsInBsYXRmIjoiMyIsInB1aWQiOiIxMDAzMjAwMDVFNEU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ml0ZSBQZW9wbGUuUmVhZCBOb3Rlcy5SZWFkV3JpdGUuQWxsIFRhc2tzLlJlYWRXcml0ZSBNYWlsLlJlYWRXcml0ZSBGaWxlcy5SZWFkV3JpdGUuQWxsIENhbGVuZGFycy5SZWFkV3JpdGUiLCJzaWduaW5fc3RhdGUiOlsia21zaSJdLCJzdWIiOiJaeVU3ajFXZC1qbVQycWVoT0xkcmZRLWpDOEJNWExpcDNKbHRjWjR4S2ZrIiwidGlkIjoiMDM0ZjhhYTgtNTUwYi00Y2ZhLTg2YTYtNzVhZDU3ZjEzZDQ5IiwidW5pcXVlX25hbWUiOiJhZG1pbkB0YWthbmExNi5vbm1pY3Jvc29mdC5jb20iLCJ1cG4iOiJhZG1pbkB0YWthbmExNi5vbm1pY3Jvc29mdC5jb20iLCJ1dGkiOiJwVjdxcFpNaVlrYXphTFdOZzU4N0FBIiwidmVyIjoiMS4wIiwid2lkcyI6WyI2MmU5MDM5NC02OWY1LTQyMzctOTE5MC0wMTIxNzcxNDVlMTAiXSwieG1zX3N0Ijp7InN1YiI6Ilp3N1NraGoxcG9wa0EySm1oV0Jta2hEdTlrTC1VUWdSY3QtM2FWYkM3djAifSwieG1zX3RjZHQiOjE1NjY1NzQ0OTR9.A7cmPDgKnGF2XsG5KqiRpTprtaEoMHzy7JdBgR0ZbNC6VjWEjGNoPfhLADaugOOXhzfT6EkD8t3KPcccFAxkAOZb7xZTnZXDnnDfh8GDMEOdiOZ2Ka-PrXCq-volPSJ_SWILi4D31rxE0oNJL_XbjMFZixcvnh8lWtMAyw6oxuQSkY8yahzVXfEH82HK8pi217OL-PPAjhDR7WH5Gc5sz2_-XlE7QbVktvmLS98nDtkXoMXbHox4TP6abta10onwlEXciPVJv_Gr1lyF490XJEyVZ7n_fOsW0rery5NRDsG9UtEFwvmLcOCi5OEYPkKMOq8eRRC0f_V-yW76JksUXQ"
$authorization = "Bearer " + $token;
$header = @{
"Accept" = "application/json"
"Authorization" = $authorization
"Content-Type" = "application/json"
}
function CallGraph($name) {
$body = @{
"displayName" = $name
"mailNickname" = $name
"mailEnabled" = $true
"securityEnabled" = $false
"groupTypes" = [string[]]"Unified"
"visibility" = "Private"
"resourceBehaviorOptions" = [string[]]"WelcomeEmailDisabled"
} | ConvertTo-Json
Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/groups/" -Method 'Post' -Body $body -Headers $header
}
#$prefix = "try250-002-"
$prefix = "wel-"
$start = 5
$count = 1
$end = $start + $count
$tries = $start..$end
$results = $tries | ForEach-Object {
$name = "$prefix{0:d3}" -f $_
$percent = 100 * ($_ - $start) / $count
Write-Progress -Activity "Creating groups" -Status "$_ of $count Complete:" -PercentComplete $percent
CallGraph($name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.