【问题标题】:Microsoft graph powershell - Can't add licenseMicrosoft graph powershell - 无法添加许可证
【发布时间】:2021-06-19 22:52:04
【问题描述】:

我正在尝试使用 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-beta

这里是完整的代码:

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。

任何想法都将不胜感激。

谢谢

【问题讨论】:

  • 使用哈希表的文档提及。所以也许试试-addlicenses @{SkuId = 'reseller-account:ENTERPRISEPACK'}
  • 老兄,你完全救了我的皮肤。 reseller-account:ENTERPRISEPACK 不起作用,但“哈希表的东西”的格式确实起作用。当我第一次尝试时,它说reseller-account:ENTERPRISEPACK 不是许可证。所以我进入了一台 Windows 计算机,并使用 azureAD 模块提取了确切的 skuid,这个:Get-AzureADSubscribedSku | Select -Property Sku*,ConsumedUnits -ExpandProperty PrepaidUnits 然后我用它来获取正确的 Skuid。我会留下一个答案。

标签: powershell


【解决方案1】:

感谢@AdminOfThings 帮助我。

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

要使用 microsoft graph powershell 在 linux 上为用户添加许可证,请使用以下命令(使用 Connect-MgGraph 模块登录 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 2021-10-16
    • 1970-01-01
    相关资源
    最近更新 更多