PowerShell を使用してセキュリティ グループを管理する
この記事は、Microsoft 365 Enterprise および Office 365 Enterprise の両方に適用されます。
PowerShell for Microsoft 365 は、セキュリティ グループを管理するための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 を使用したグループを管理する