#MicrosoftGraph #Graph
Microsoft Graph
Microsoft graph Groups API
Microsoft Graph Explorer,Powershell, Postman
Endpoints, Metadata and Permissions required for groups
List of all the attributes and Related Objects
Delta Endpoints for groups
Script to create groups from CSV
Use postman to access Microsoft Graph - • Oauth 2.0 Client Credential Flow | Mi...
Microsoft Article - https://docs.microsoft.com/en-us/grap...
NOTE – Make sure you update client id and client secret value for one of your application.
Most Important – Update the exact file path for CSV.
#########################################SCRIPT BEGINS######################################
Write-Host "This script will help you create group from CSV file"
Write-Host "This group required Group.ReadWrite.All"
$tenant = Read-Host ('Enter your Tenant Name')
Write-Host Tenant name you entered is $tenant
$Openid = Invoke-RestMethod -uri "https://login.microsoftonline.com/$te..."
$tokenendpoint = $Openid.token_endpoint
$Body = @{
client_id = "fb1634a9-8efe-96501ba" #Replace this value with your applications client ID#
client_secret = "860FV _I-0DzFv0d_4tVI~ " #Replace this value with your applications client secret#
redirect_uri = "https://localhost/15487" #Make sure you have added this value in redirect URI#
grant_type = "client_credentials"
scope = "https://graph.microsoft.com/.default"
response_type = "code"
tenant = "$tenant"
}
Write-Host "Requesting AccessToken"
$token = Invoke-RestMethod -uri $tokenendpoint -Body $Body -Method Post
if ($token -eq $null)
{
Write-Host Unable to Acquire Access Token -ForegroundColor Red
Write-Host Script is exiting -ForegroundColor Red
Write-Host "There must be some parameter missing or wrong in body Object" -ForegroundColor Red
exit
}
else
{
Write-Host "Successfully retrieved Access Token"
Write-Host "Importing CSV"
Write-Host "Make sure that you have specified the exact CSV path"
$groups = Import-Csv -Path f:\group.csv -Header 'Description','DisplayName','MailEnabled','MailNickName','SecurityEnabled','owner'
#Foreachloop to query each row for group Object
foreach ($group in $groups)
{
$apiUrl = 'https://graph.microsoft.com/v1.0/groups' #GroupEndpoint
$groupowner = $group.owner #QueryingOwnerUPN
$group = @{
description = $group.Description
displayName = $group.DisplayName
mailEnabled = $group.MailEnabled
mailNickName = $group.MailNickName
securityEnabled = $group.SecurityEnabled
}
$request = $group | ConvertTo-Json #Converting Object to Json
#creating Group
$CreateGroup = Invoke-RestMethod -Headers @{Authorization = "Bearer $($token.access_token)"} -Uri $apiUrl -Method POST -ContentType 'application/json' -body $request
#selecting group ObjectID of the group
$groupid = $CreateGroup.id
Write-Host "Querying id of Group Owner"
$Owneridurl = "https://graph.microsoft.com/v1.0/user..."
$QueryObjectIdofOwner = Invoke-RestMethod -Headers @{Authorization = "Bearer $($token.access_token)"} -Uri $Owneridurl -Method Get
$objectidofowner = $QueryObjectIdofOwner.id
Write-Host "ObjectId of the Owner" $objectidofowner
Write-Host "Adding Owner $groupowner"
$Addownerurl = "https://graph.microsoft.com/v1.0/grou..." + '$ref'
$GroupOwnerRef = @{
'@odata.id' = "https://graph.microsoft.com/v1.0/dire..."
}
$JsonGroupOwner = $GroupOwnerRef | ConvertTo-Json
$AddingOwner = Invoke-RestMethod -Headers @{Authorization = "Bearer $($token.access_token)"} -Uri $AddOwnerurl -Method Post -body $JsonGroupOwner -ContentType 'application/json'
}
}
#########################################SCRIPT ENDS######################################
In questa pagina del sito puoi guardare il video online Microsoft Graph Groups Script della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Concepts Work 01 gennaio 1970, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 1,682 volte e gli è piaciuto 15 spettatori. Buona visione!