Share via


PowerShell을 사용하여 보안 그룹 관리

이 문서는 Microsoft 365 Enterprise와 Office 365 Enterprise에 모두 적용됩니다.

보안 그룹을 관리하는 Microsoft 365 관리 센터 대신 Microsoft 365용 PowerShell을 사용할 수 있습니다.

이 문서에서는 보안 그룹 나열, 만들기, 설정 변경 및 제거에 대해 설명합니다.

이 문서의 명령 블록에서 변수 값을 지정해야 하는 경우 다음 단계를 사용합니다.

  1. 명령 블록을 클립보드에 복사하여 메모장 또는 PowerShell ISE(통합 스크립트 환경)에 붙여넣습니다.
  2. 변수 값을 입력하고 "" 및 "<>" 문자를 제거합니다.
  3. PowerShell 창 또는 PowerShell ISE에서 명령을 실행합니다.

PowerShell을 사용하여 그룹 멤버 자격을 관리하려면 보안 그룹 멤버 자격 유지 관리를 참조하세요.

Microsoft Graph PowerShell을 사용하여 보안 그룹 관리

참고

Azure Active Directory 모듈은 Microsoft Graph PowerShell SDK로 대체됩니다. Microsoft Graph PowerShell SDK를 사용하여 모든 Microsoft Graph API에 액세스할 수 있습니다. 자세한 내용은 Microsoft Graph PowerShell SDK 시작하기를 참조하세요.

먼저 Microsoft 365 테넌트에서 연결합니다.

보안 그룹을 관리하려면 Group.ReadWrite.All 권한 scope 또는 'list subscribedSkus' Graph API 참조 페이지에 나열된 다른 권한 중 하나가 필요합니다. 이 문서의 일부 명령에는 다른 사용 권한 범위가 필요할 수 있으며, 이 경우 관련 섹션에 설명되어 있습니다.

Connect-Graph -Scopes Group.ReadWrite.All

그룹 나열

이 명령을 사용하여 모든 그룹을 나열합니다.

Get-MgGroup -All

이러한 명령을 사용하여 표시 이름으로 특정 그룹의 설정을 표시합니다.

$groupName="<display name of the group>"
Get-MgGroup -All | Where-Object { $_.DisplayName -eq $groupName }

새 그룹 만들기

이 명령을 사용하여 새 보안 그룹을 만듭니다.

Connect-MgGraph -Scopes "Group.Create"
New-MgGroup -Description "<group purpose>" -DisplayName "<name>" -MailEnabled:$false -SecurityEnabled -MailNickname "<email name>"

그룹의 설정 표시

이러한 명령을 사용하여 그룹의 설정을 표시합니다.

$groupName="<display name of the group>"
Get-MgGroup -All | Where-Object { $_.DisplayName -eq $groupName } | Select-Object *

보안 그룹 제거

이러한 명령을 사용하여 보안 그룹을 제거합니다.

$groupName="<display name of the group>"
$group = Get-MgGroup -Filter "displayName eq '$groupName'"
Remove-MgGroup -GroupId $group.Id

보안 그룹의 소유자 관리

이러한 명령을 사용하여 보안 그룹의 현재 소유자를 표시합니다.

$groupName="<display name of the group>"

# Connect to Microsoft Graph
Connect-MgGraph -Scopes "GroupMember.Read.All"

# Display group owners
Get-MgGroupOwner -GroupId (Get-MgGroup | Where-Object { $_.DisplayName -eq $groupName }).Id

이러한 명령을 사용하여 보안 그룹의 현재 소유자에게 UPN(사용자 계정 이름)으로 사용자 계정을 추가합니다.

$userUPN="<UPN of the user account to add>"
$groupName="<display name of the group>"

# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Group.ReadWrite.All", "User.ReadBasic.All"

# Get the group and user
$group = Get-MgGroup -Filter "displayName eq '$groupName'"
$userId = (Get-MgUser -Filter "userPrincipalName eq '$userUPN'").Id

# Add the user as an owner to the group
$newGroupOwner =@{
  "@odata.id"= "https://graph.microsoft.com/v1.0/users/$userId"
  }

New-MgGroupOwnerByRef -GroupId $group.Id -BodyParameter $newGroupOwner

이러한 명령을 사용하여 표시 이름으로 사용자 계정을 보안 그룹의 현재 소유자에게 추가합니다.

$userName="<Display name of the user account to add>"
$groupName="<display name of the group>"

# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Group.ReadWrite.All", "Directory.Read.All", "User.ReadBasic.All"

# Get the group and user
$group = Get-MgGroup -All | Where-Object { $_.DisplayName -eq $groupName }
$userId = (Get-MgUser -All | Where-Object { $_.DisplayName -eq $userName }).Id

# Add the user as an owner to the group
$newGroupOwner =@{
  "@odata.id"= "https://graph.microsoft.com/v1.0/users/$userId"
  }

New-MgGroupOwnerByRef -GroupId $group.Id -BodyParameter $newGroupOwner

이러한 명령을 사용하여 보안 그룹의 현재 소유자에서 UPN 으로 사용자 계정을 제거합니다.

$userUPN="<UPN of the user account to remove>"
$groupName="<display name of the group>"

# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Group.ReadWrite.All", "Directory.ReadWrite.All"

# Get the group and user
$group = Get-MgGroup -Filter "displayName eq '$groupName'" | Select-Object -First 1
$user = Get-MgUser -Filter "userPrincipalName eq '$userUPN'" | Select-Object -First 1

# Remove the user from the group
Remove-MgGroupOwnerByRef -GroupId $group.Id -DirectoryObjectId $user.Id

이러한 명령을 사용하여 보안 그룹의 현재 소유자에서 표시 이름으로 사용자 계정을 제거합니다.

$userName="<Display name of the user account to remove>"
$groupName="<display name of the group>"
$group = Get-MgGroup | Where-Object { $_.DisplayName -eq $groupName }
$user = Get-MgUser | Where-Object { $_.DisplayName -eq $userName }

Remove-MgGroupOwnerByRef -GroupId $group.Id -DirectoryObjectId $user.Id

참고 항목

PowerShell로 Microsoft 365 사용자 계정, 라이선스 및 그룹 관리

PowerShell로 Microsoft 365 관리

Microsoft 365 용 PowerShell 시작