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 Graph PowerShell SDK를 사용하여 사용자 계정에 Microsoft 365 라이선스 할당

참고

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

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

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

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

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

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

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

organization 허가되지 않은 계정을 찾으려면 이 명령을 실행합니다.

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

organization 허가되지 않은 동기화된 사용자를 찾으려면 이 명령을 실행합니다.

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

UsageLocation 속성이 유효한 ISO 3166-1 alpha-2 국가 코드로 설정된 사용자 계정에만 라이선스를 할당할 수 있습니다. 예를 들어 미국 경우 미국, 프랑스의 경우 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 @()

이 예제에서는 사용자에게belindan@litwareinc.comSPE_E5(Microsoft 365 E5) 및 EMSPREMIUM(ENTERPRISE MOBILITY + SECURITY E5)을 할당합니다.

$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 사용자 사용: assignLicensesubscribedSku API