PowerShell을 사용하여 사용자 계정에 Microsoft 365 라이선스 할당

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

사용자는 계정에 라이선스 계획의 라이선스가 할당될 때까지 Microsoft 365 서비스를 사용할 수 없습니다. PowerShell을 사용하여 라이선스가 없는 계정에 라이선스를 빠르게 할당할 수 있습니다.

사용자 계정에는 먼저 위치가 할당되어야 합니다. 위치를 지정하는 것은 Microsoft 365 관리 센터에서 새 사용자 계정을 만드는 데 필요한 부분입니다.

온-프레미스 Active Directory Domain Services에서 동기화된 계정에는 기본적으로 위치가 지정되어 있지 않습니다. 다음에서 이러한 계정의 위치를 구성할 수 있습니다.

  • Microsoft 365 관리 센터
  • PowerShell
  • Azure Portal(Active Directory>사용자>, 사용자 계정>, 프로필,>연락처 정보>, 국가 또는 지역).

참고

Microsoft 365 관리 센터를 사용하여 사용자 계정에 라이선스를 할당하는 방법을 알아봅니다. 추가 리소스 목록은 사용자 및 그룹 관리를 참조하세요.

Microsoft Graph PowerShell SDK를 사용하여 사용자 계정에 Microsoft 365 라이선스 할당

참고

다음 스크립트는 Microsoft Graph Powershell을 사용합니다. 자세한 내용은 Microsoft Graph PowerShell 개요를 참조하세요.

다양한 방법을 사용하여 무인 스크립트에서 인증 Connect-Graph 하는 방법에 대한 자세한 내용은 Microsoft Graph PowerShell의 인증 모듈 cmdlet 문서를 참조하세요.

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

사용자에 대한 라이선스를 할당하고 제거하려면 User.ReadWrite.All 권한 범위 또는 '라이선스 할당' Microsoft Graph API 참조 페이지에 나열된 다른 권한 중 하나가 필요합니다.

테넌트에서 사용할 수 있는 라이선스를 읽으려면 Organization.Read.All 권한 범위가 필요합니다.

Connect-MgGraph -Scopes User.ReadWrite.All, Organization.Read.All

명령을 실행 Get-MgSubscribedSku 하여 사용 가능한 라이선스 계획과 조직의 각 계획에서 사용 가능한 라이선스 수를 확인합니다. 각 플랜에서 사용 가능한 라이선스 수는 ActiveUnits - WarningUnits - ConsumedUnits입니다. 라이선스 계획, 라이선스 및 서비스에 대한 자세한 내용은 PowerShell을 사용하여 라이선스 및 서비스 보기를 참조하세요.

조직에서 사용이 허가되지 않은 계정을 찾으려면 이 명령을 실행합니다.

Get-MgUser -Filter 'assignedLicenses/$count eq 0' -ConsistencyLevel eventual -CountVariable unlicensedUserCount -All

조직에서 라이선스가 없는 동기화된 사용자를 찾으려면 이 명령을 실행합니다.

Get-MgUser -Filter 'assignedLicenses/$count eq 0 and OnPremisesSyncEnabled eq true' -ConsistencyLevel eventual -CountVariable unlicensedUserCount -All -Select UserPrincipalName

UsageLocation 속성이 유효한 ISO 3166-1 alpha-2 국가 코드로 설정된 사용자 계정에만 라이선스를 할당할 수 있습니다. 예를 들어 미국은 US, 프랑스는 FR입니다. 일부 Microsoft 365 서비스는 특정 국가/지역에서 사용할 수 없습니다. 자세한 내용은 라이선스 제한 정보를 참조하세요.

UsageLocation 값이 없는 계정을 찾으려면 이 명령을 실행합니다.

Get-MgUser -Select Id,DisplayName,Mail,UserPrincipalName,UsageLocation,UserType | where { $_.UsageLocation -eq $null -and $_.UserType -eq 'Member' }

계정에 대한 UsageLocation 값을 설정하려면 이 명령을 실행합니다.

$userUPN="<user sign-in name (UPN)>"
$userLoc="<ISO 3166-1 alpha-2 country code>"

Update-MgUser -UserId $userUPN -UsageLocation $userLoc

예시:

Update-MgUser -UserId "belindan@litwareinc.com" -UsageLocation US

-All 매개 변수를 사용하지 않고 Get-MgUser cmdlet을 사용하면 처음 100개 계정만 반환됩니다.

사용자 계정에 라이선스 할당

사용자에게 라이선스를 할당하려면 PowerShell에서 다음 명령을 사용합니다.

Set-MgUserLicense -UserId $userUPN -AddLicenses @{SkuId = "<SkuId>"} -RemoveLicenses @()

이 예제에서는 SPE_E5 (Microsoft 365 E5) 라이선스 계획의 라이선스를 라이선스가 없는 사용자에게 belindan@litwareinc.com할당합니다.

$e5Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E5'
Set-MgUserLicense -UserId "belindan@litwareinc.com" -AddLicenses @{SkuId = $e5Sku.SkuId} -RemoveLicenses @()

이 예제에서는 SPE_E5 (Microsoft 365 E5) 및 EMSPREMIUM (엔터프라이즈 모빌리티 + 보안 E5)을 사용자에게 belindan@litwareinc.com할당합니다.

$e5Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E5'
$e5EmsSku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'EMSPREMIUM'
$addLicenses = @(
    @{SkuId = $e5Sku.SkuId},
    @{SkuId = $e5EmsSku.SkuId}
)

Set-MgUserLicense -UserId "belinda@litwareinc.com" -AddLicenses $addLicenses -RemoveLicenses @()

이 예에서는 MICROSOFTBOOKINGS(Microsoft Bookings) 및 LOCKBOX_ENTERPRISE(고객 Lockbox) 서비스가 해제된 상태에서 SPE_E5(Microsoft 365 E5)를 할당합니다.

$e5Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E5'
$disabledPlans = $e5Sku.ServicePlans | `
    Where ServicePlanName -in ("LOCKBOX_ENTERPRISE", "MICROSOFTBOOKINGS") | `
    Select -ExpandProperty ServicePlanId

$addLicenses = @(
    @{
        SkuId = $e5Sku.SkuId
        DisabledPlans = $disabledPlans
    }
)

Set-MgUserLicense -UserId "belinda@litwareinc.com" -AddLicenses $addLicenses -RemoveLicenses @()

이 예제에서는 SPE_E5 (Microsoft 365 E5)로 사용자를 업데이트하고 Sway 및 Forms 서비스 계획을 끄는 동시에 사용자의 기존 비활성화 플랜을 현재 상태로 둡니다.

$userLicense = Get-MgUserLicenseDetail -UserId "belinda@litwareinc.com"
$userDisabledPlans = $userLicense.ServicePlans | `
    Where ProvisioningStatus -eq "Disabled" | `
    Select -ExpandProperty ServicePlanId

$e5Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E5'
$newDisabledPlans = $e5Sku.ServicePlans | `
    Where ServicePlanName -in ("SWAY", "FORMS_PLAN_E5") | `
    Select -ExpandProperty ServicePlanId

$disabledPlans = ($userDisabledPlans + $newDisabledPlans) | Select -Unique

$addLicenses = @(
    @{
        SkuId = $e5Sku.SkuId
        DisabledPlans = $disabledPlans
    }
)

Set-MgUserLicense -UserId "belinda@litwareinc.com" -AddLicenses $addLicenses -RemoveLicenses @()

이 예에서는 SPE_E5 (Microsoft 365 E5)로 사용자를 업데이트하고 Sway 및 Forms 서비스 플랜을 끄는 동시에 사용자의 다른 모든 구독의 기존 비활성화 플랜은 현재 상태로 둡니다.

$userLicense = Get-MgUserLicenseDetail -UserId belinda@litwareinc.com

$userDisabledPlans = $userLicense.ServicePlans | Where-Object ProvisioningStatus -eq "Disabled" | Select -ExpandProperty ServicePlanId

$e5Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E5'

$newDisabledPlans = $e5Sku.ServicePlans | Where ServicePlanName -in ("SWAY", "FORMS_PLAN_E5") | Select -ExpandProperty ServicePlanId

$disabledPlans = ($userDisabledPlans + $newDisabledPlans) | Select -Unique

$result=@()
$allPlans = $e5Sku.ServicePlans | Select -ExpandProperty ServicePlanId

foreach($disabledPlan in $disabledPlans)
{
    foreach($allPlan in $allPlans)
    {
        if($disabledPlan -eq $allPlan)
        {
            $property = @{
                Disabled = $disabledPlan
            }
        }
     }
     $result += New-Object psobject -Property $property
}


$finalDisabled = $result | Select-Object -ExpandProperty Disabled


$addLicenses = @(
    @{
        SkuId = $e5Sku.SkuId
        DisabledPlans = $finalDisabled
    }
)


Set-MgUserLicense -UserId belinda@litwareinc.com -AddLicenses $addLicenses -RemoveLicenses @()

다른 사용자의 라이선스 할당을 복사하여 사용자에게 라이선스 할당

이 예에서는 다음에 적용된 것과 동일한 라이선스 플랜을 할당 jamesp@litwareinc.com 합니다.belindan@litwareinc.com

$mgUser = Get-MgUser -UserId "belindan@litwareinc.com" -Property AssignedLicenses
Set-MgUserLicense -UserId "jamesp@litwareinc.com" -AddLicenses $mgUser.AssignedLicenses -RemoveLicenses @()

사용자를 다른 구독(라이선스 플랜)으로 이동

이 예에서는 사용자를 SPE_E3 (Microsoft 365 E3) 라이선스 계획에서 SPE_E5 (Microsoft 365 E5) 라이선스 계획으로 업그레이드합니다.

$e3Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E3'
$e5Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E5'

# Unassign E3
Set-MgUserLicense -UserId "belindan@litwareinc.com" -AddLicenses @{} -RemoveLicenses @($e3Sku.SkuId)
# Assign E5
Set-MgUserLicense -UserId "belindan@litwareinc.com" -AddLicenses @{SkuId = $e5Sku.SkuId} -RemoveLicenses @()

이 명령을 사용하여 사용자 계정에 대한 구독 변경을 확인할 수 있습니다.

Get-MgUserLicenseDetail -UserId "belindan@litwareinc.com"

참고 항목

PowerShell로 Microsoft 365 관리

PowerShell로 Microsoft 365 관리

Microsoft Graph PowerShell SDK 시작하기

Microsoft Graph 사용자: assignLicense 및 subscribedSku API 사용