共用方式為


Set-AzureADUserLicense

將 Microsoft 在線服務的授權新增或移除至使用者指派的授權清單。

注意

Set-AzureADUserLicense Cmdlet 已被取代。 瞭解如何使用 Microsoft Graph PowerShell 指派授權。 如需詳細資訊,請參閱 指派授權 Microsoft Graph API。

語法

Set-AzureADUserLicense
   -ObjectId <String>
   -AssignedLicenses <AssignedLicenses>
   [-InformationAction <ActionPreference>]
   [-InformationVariable <String>]
   [<CommonParameters>]

Description

Set-AzureADUserLicense 會將 Microsoft 在線服務的授權新增或移除至使用者指派的授權清單。

範例

範例 1:根據範本用戶將授權新增至使用者

PS C:\> $LicensedUser = Get-AzureADUser -ObjectId "TemplateUser@contoso.com"  
PS C:\> $User = Get-AzureADUser -ObjectId "User@contoso.com"  
PS C:\> $License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense 
PS C:\> $License.SkuId = $LicensedUser.AssignedLicenses.SkuId 
PS C:\> $Licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses 
PS C:\> $Licenses.AddLicenses = $License 
PS C:\> Set-AzureADUserLicense -ObjectId $User.ObjectId -AssignedLicenses $Licenses

第一個命令會使用 Get-AzureADUser Cmdlet 取得使用者,然後將它儲存在$LicensedUser變數中。

第二個命令會使用 Get-AzureADUser 取得另一位使用者,然後將它儲存在$User變數中。

第三個命令會建立 AssignedLicense 類型,然後將它儲存在$License變數中。

第四個命令會將 $License 的 SkuId 屬性設定為與 $LicensedUser 的 SkuId 屬性相同的值。

第五個命令會建立 AssignedLicenses 物件,並將它儲存在$Licenses變數中。

第六個命令會將 $License 中的授權新增至 $Licenses。

最後一個命令會將 $Licenses 中的授權指派給 $User 中的使用者。 $Licenses中的授權包含第三和第四個命令中的$License。

參數

-AssignedLicenses

指定要指派或移除的授權清單。

類型:AssignedLicenses
Position:Named
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False

-InformationAction

指定此 Cmdlet 如何回應資訊事件。 此參數可接受的值為:

  • 繼續
  • 忽略
  • 詢問
  • SilentlyContinue
  • Stop
  • 暫止
類型:ActionPreference
別名:infa
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-InformationVariable

指定資訊變數。

類型:String
別名:iv
Position:Named
預設值:None
必要:False
接受管線輸入:False
接受萬用字元:False

-ObjectId

指定使用者在 Azure AD 中 (為 UPN 或 ObjectId) 的識別碼。

類型:String
Position:Named
預設值:None
必要:True
接受管線輸入:True
接受萬用字元:False