Graph API を使ってグループに関する操作を行う際の Invoke-MgGraphRequest での基本的な記述について確認をしたもの。
$group=Get-MgGroup -Filter "mail eq 'Mail'";
$group=Get-MgGroup -Filter "displayName eq 'DisplayName'";
Microsoft Learn:Get group - Microsoft Graph v1.0
Microsoft Learn:List group members - Microsoft Graph v1.0
Microsoft Learn:List memberOf - Microsoft Graph v1.0
Connect-MgGraph -Scopes 'GroupMember.Read.All'
[PSCustomObject](Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/groups/$($group.Id)")
$response=Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/groups/$($group.Id)/members"; Foreach($item in $response.value){[PSCustomObject]$item}
$response=Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/groups/$($group.Id)/memberof"; Foreach($item in $response.value){[PSCustomObject]$item}
Disconnect-MgGraph
Microsoft Learn:Update group - Microsoft Graph v1.0
Connect-MgGraph -Scopes 'Group.ReadWrite.All'
Invoke-MgGraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/groups/$($group.Id)" -Body @{'description'='description of group except for distribution lists';}
Disconnect-MgGraph
Microsoft Learn:Manage Groups in Microsoft Graph - Microsoft Graph v1.0
Microsoft Learn:Advanced query capabilities on Microsoft Entra ID objects - Microsoft Graph
メールが有効なセキュリティグループの判別には visibility が空白、securityEnabled が True、mailEnabled が True を確認するというものもある。しかしクエリで visibility プロパティは利用できず groupTypes プロパティを利用することになるが、NOT演算子を使用するため高度なクエリ機能が必要になる。
Connect-MgGraph -Scopes 'GroupMember.Read.All'
$response=Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/groups/?`$filter=NOT groupTypes/any(c:c eq 'Unified') and mailEnabled eq true and securityEnabled eq true&`$count=true" -Headers @{ConsistencyLevel='eventual'}; Foreach($item in $response.value){[PSCustomObject]$item}
Disconnect-MgGraph
$group=Get-MgGroup -Filter "mail eq 'Mail'";
$group=Get-MgGroup -Filter "displayName eq 'DisplayName'";
Microsoft Learn:Get group - Microsoft Graph v1.0
Microsoft Learn:List group members - Microsoft Graph v1.0
Microsoft Learn:List memberOf - Microsoft Graph v1.0
Connect-MgGraph -Scopes 'GroupMember.Read.All'
[PSCustomObject](Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/groups/$($group.Id)")
$response=Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/groups/$($group.Id)/members"; Foreach($item in $response.value){[PSCustomObject]$item}
$response=Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/groups/$($group.Id)/memberof"; Foreach($item in $response.value){[PSCustomObject]$item}
Disconnect-MgGraph
Microsoft Learn:Update group - Microsoft Graph v1.0
Connect-MgGraph -Scopes 'Group.ReadWrite.All'
Invoke-MgGraphRequest -Method PATCH -Uri "https://graph.microsoft.com/v1.0/groups/$($group.Id)" -Body @{'description'='description of group except for distribution lists';}
Disconnect-MgGraph
Microsoft Learn:Manage Groups in Microsoft Graph - Microsoft Graph v1.0
Microsoft Learn:Advanced query capabilities on Microsoft Entra ID objects - Microsoft Graph
メールが有効なセキュリティグループの判別には visibility が空白、securityEnabled が True、mailEnabled が True を確認するというものもある。しかしクエリで visibility プロパティは利用できず groupTypes プロパティを利用することになるが、NOT演算子を使用するため高度なクエリ機能が必要になる。
Connect-MgGraph -Scopes 'GroupMember.Read.All'
$response=Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/groups/?`$filter=NOT groupTypes/any(c:c eq 'Unified') and mailEnabled eq true and securityEnabled eq true&`$count=true" -Headers @{ConsistencyLevel='eventual'}; Foreach($item in $response.value){[PSCustomObject]$item}
Disconnect-MgGraph