首页 > 解决方案 > Microsoft graph powershell - 无法添加许可证

问题描述

我正在尝试使用向用户添加许可证Set-MgUserLicense但是我收到错误:Set-MgUserLicense: Cannot process argument transformation on parameter 'AddLicenses'.

主要问题是我需要帮助以他们想要的正确方式放置许可证 sku。但是我无法在线或从文档中找到示例:https ://docs.microsoft.com/en-us/powershell/module/microsoft.graph.users.actions/set-mguserlicense?view=graph-powershell -β

这是完整的代码:

Set-MgUserLicense -UserId "testuser@testuser.com" -addLicenses [SkuId:reseller-account:ENTERPRISEPACK] -RemoveLicenses @() 

这是完整的错误:

Set-MgUserLicense: Cannot process argument transformation on parameter 'AddLicenses'. 
Cannot convert value "[SkuId:reseller-account:ENTERPRISEPACK]" to type "Microsoft.Graph.PowerShell.Models.IMicrosoftGraphAssignedLicense[]". 
Error: "Cannot convert the "[SkuId:reseller-account:ENTERPRISEPACK]" value of type "System.String" to type "Microsoft.Graph.PowerShell.Models.IMicrosoftGraphAssignedLicense"."

我也试过: reseller-account:ENTERPRISEPACK

SkuId:reseller-account:ENTERPRISEPACK

两者都给出相同类型的错误。

我通过在 Windows 计算机上使用 MSOnline 获得了 SKU。

AccountSkuId                            ActiveUnits WarningUnits ConsumedUnits
------------                            ----------- ------------ -------------
reseller-account:ENTERPRISEPACK         31          0            30           
reseller-account:FLOW_FREE              10000       0            5            
reseller-account:CCIBOTS_PRIVPREV_VIRAL 10000       0            1            
reseller-account:POWER_BI_STANDARD      1000000     0            2            
reseller-account:TEAMS_EXPLORATORY      100         0            2            
reseller-account:MCOMEETADV             1           0            1            

我本来只是使用 MSOnline 向用户添加许可证,但这不适用于 powershell.core,这意味着它不适用于 linux。

任何想法,将不胜感激。

谢谢

标签: powershell

解决方案


感谢@AdminOfThings 帮助我。

基本上我需要一个东西的格式Hash Table。我说“thingy”是因为我还不知道哈希表是什么,但这很有效。

Connect-MgGraph要使用 microsoft graph powershell 在 linux 上为用户添加许可证,请使用以下命令(使用模块登录到 Microsoft graph 后)

Set-MgUserLicense -UserId "Enteremail@emailinquestion.com" -addlicenses @{SkuId = 'ENTER_A_SKUID_HERE'} -RemoveLicenses @() 

一个大问题是,当我尝试获取它时,skuid它会给我名称而不是实际的 SkuID。为此,我需要使用 Windows 计算机来使用 AzureAD 模块来获取 skuid。(注意:AzureAD 模块不能在 Linux 上运行,powershell.core 不支持它)

#Install the module
Install-Module -Name AzureAD

#Connect to the module
Connect-AzureAD

#Use this to get your Skuid, and copy/paste that into your Set-MgUserLicense command
Get-AzureADSubscribedSku | Select -Property Sku*,ConsumedUnits -ExpandProperty PrepaidUnits

推荐阅读