PowerShell を使用してセキュリティ グループを管理する
この記事は、Microsoft 365 Enterprise および Office 365 Enterprise の両方に適用されます。
セキュリティ グループを管理するMicrosoft 365 管理センターの代わりに、PowerShell for Microsoft 365 を使用できます。
この記事では、セキュリティ グループの一覧表示、作成、設定の変更、および削除について説明します。
この記事のコマンド ブロックで変数値を指定する必要がある場合は、次の手順を使用します。
- コマンド ブロックをクリップボードにコピーし、メモ帳または PowerShell 統合スクリプト環境 (ISE) に貼り付けます。
- 変数の値を入力し、"<" 文字と "" 文字を>削除します。
- PowerShell ウィンドウまたは PowerShell ISE でコマンドを実行します。
PowerShell を使用してグループ メンバーシップを管理するための セキュリティ グループ メンバーシップの管理に関するページを参照してください。
Graph 用 Azure Active Directory PowerShell モジュールを使用する
グループを一覧表示する
このコマンドを使用して、すべてのグループを一覧表示します。
Get-AzureADGroup
これらのコマンドを使用して、特定のグループの設定を表示名で表示します。
$groupName="<display name of the group>"
Get-AzureADGroup | Where { $_.DisplayName -eq $groupName }
新しいグループを作成する
このコマンドを使用して、新しいセキュリティ グループを作成します。
New-AzureADGroup -Description "<group purpose>" -DisplayName "<name>" -MailEnabled $false -SecurityEnabled $true -MailNickName "<email name>"
グループの設定を変更する
これらのコマンドを使用してグループの設定を表示します。
$groupName="<display name of the group>"
Get-AzureADGroup | Where { $_.DisplayName -eq $groupName } | Select *
次に、 Set-AzureADGroup の記事を使用して、設定を変更する方法を決定します。
セキュリティ グループを削除する
これらのコマンドを使用して、セキュリティ グループを削除します。
$groupName="<display name of the group>"
Remove-AzureADGroup -ObjectId (Get-AzureADGroup | Where { $_.DisplayName -eq $groupName }).ObjectId
セキュリティ グループの所有者を管理する
これらのコマンドを使用して、セキュリティ グループの現在の所有者を表示します。
$groupName="<display name of the group>"
Get-AzureADGroupOwner -ObjectId (Get-AzureADGroup | Where { $_.DisplayName -eq $groupName }).ObjectId
これらのコマンドを使用して、ユーザー プリンシパル名 (UPN) でユーザー アカウントをセキュリティ グループの現在の所有者に追加します。
$userUPN="<UPN of the user account to add>"
$groupName="<display name of the group>"
Add-AzureADGroupOwner -ObjectId (Get-AzureADGroup | Where { $_.DisplayName -eq $groupName }).ObjectId -RefObjectId (Get-AzureADUser | Where { $_.UserPrincipalName -eq $userUPN }).ObjectId
これらのコマンドを使用して、 表示名 でユーザー アカウントをセキュリティ グループの現在の所有者に追加します。
$userName="<Display name of the user account to add>"
$groupName="<display name of the group>"
Add-AzureADGroupOwner -ObjectId (Get-AzureADGroup | Where { $_.DisplayName -eq $groupName }).ObjectId -RefObjectId (Get-AzureADUser | Where { $_.DisplayName -eq $userName }).ObjectId
次のコマンドを使用して、 UPN によってユーザー アカウントをセキュリティ グループの現在の所有者に削除します。
$userUPN="<UPN of the user account to remove>"
$groupName="<display name of the group>"
Remove-AzureADGroupOwner -ObjectId (Get-AzureADGroup | Where { $_.DisplayName -eq $groupName }).ObjectId -OwnerId (Get-AzureADUser | Where { $_.UserPrincipalName -eq $userUPN }).ObjectId
これらのコマンドを使用して、 表示名 でユーザー アカウントをセキュリティ グループの現在の所有者に削除します。
$userName="<Display name of the user account to remove>"
$groupName="<display name of the group>"
Remove-AzureADGroupOwner -ObjectId (Get-AzureADGroup | Where { $_.DisplayName -eq $groupName }).ObjectId -OwnerId (Get-AzureADUser | Where { $_.DisplayName -eq $userName }).ObjectId
Windows PowerShell 用 Microsoft Azure Active Directory モジュールを使用する
グループを一覧表示する
このコマンドを使用して、すべてのグループを一覧表示します。
Get-MsolGroup
これらのコマンドを使用して、特定のグループの設定を表示名で表示します。
$groupName="<display name of the group>"
Get-MsolGroup | Where { $_.DisplayName -eq $groupName }
新しいグループを作成する
このコマンドを使用して、新しいセキュリティ グループを作成します。
New-MsolGroup -Description "<group purpose>" -DisplayName "<name>"
グループの設定を変更する
これらのコマンドを使用してグループの設定を表示します。
$groupName="<display name of the group>"
Get-MsolGroup | Where { $_.DisplayName -eq $groupName } | Select *
次に、 Set-MsolGroup の記事を使用して、設定を変更する方法を決定します。
セキュリティ グループを削除する
これらのコマンドを使用して、セキュリティ グループを削除します。
$groupName="<display name of the group>"
Remove-MsolGroup -ObjectId (Get-AzureADGroup | Where { $_.DisplayName -eq $groupName }).ObjectId
関連項目
Microsoft 365 ユーザー アカウント、ライセンス、PowerShell を使用したグループを管理する