Ste*_*adH 6 powershell active-directory microsoft-office-365 azure-active-directory
我正在尝试做一些我认为修复起来不会太复杂的事情。我的最终目标:我在一个 AD OU 中的某些用户需要使用 Office 365 中的某个许可证,而另一个 OU 中的不同用户需要获得不同的许可证。
我想运行的命令是:
Get-ADUser -Filter * -SearchBase "ou=test,dc=our,dc=domain,dc=edu" | Set-MsolUserLicense -AddLicenses ourorg:STANDARDWOFFPACK_IW_STUDENT
Run Code Online (Sandbox Code Playgroud)
但这失败了:
Set-MsolUserLicense : The input object cannot be bound because it did not contain the information required to bind all mandatory parameters: ObjectId At line:1 char:111 + Get-ADUser -Filter * -SearchBase "ou=Test students,ou=Students,dc=campus,dc=org,dc=edu" | Set-MsolUserLicense <<<< -AddLicenses nwcu:STANDARDWOFFPACK_IW_STUDENT
单独地,这两个命令都有效。我可以选择 OU 中的所有用户,也可以手动使用 Set-MsolUserLicense 命令和 -UserPrincipalName 来许可单个用户。
这是因为 Get-ADUser 没有像 Set-MsolUserLicense 正在寻找的那样返回 ObjectID 吗?Get-ADUser 确实返回 ObjectGUID。如果我在这里走在正确的轨道上,有没有办法将这些映射到管道输入?
编辑:我知道这样做的流行方法涉及为此上传 CSV 文件,并且我知道我可以 CSV 导出这些用户,但我已经在 OU 中将它们整理得如此整洁,所以我很乐意这样做如果可能的话,现在导入/导出。
提前致谢!
您肯定想使用 for-each 循环来枚举每个用户并应用许可证。.UserPrincipalName该循环需要从查询中返回的每个对象中调用Get-ADUser,因为 Office365 在设置许可证时需要使用该值:
Get-ADUser | %{ Set-MSOLUserLicense -UserPrincipalName $_.UserPrincipalName }
Run Code Online (Sandbox Code Playgroud)
我在这里创建了自己的答案来解释我认为您在问题中描述的一个常见情况:您不想将相同的许可证选项全面应用于每个人。
关于此事的TechNet 博客非常有帮助。由于数据泄露原因,您可能不希望财务团队访问 SharePoint Online/OneDrive for Business,或者您可能不想为 Lync/Skype for Business 启用呼叫中心。
要获取有关租户的信息,请从顶部开始:
Get-MSOLAccountSku
这将返回您在租户中拥有的许可证包。一些常见的 SKU 是 ENTERPRISEPACK 和 DESKLESPACK。这些将在yourorg:LICENSEPACKAccountSkuId 下列出。
请务必注意,当您通过 PowerShell 申请时,每个许可证包的功能都可能被禁用(同样,您可以选择选中/取消选中管理中心中的选项框)。

要创建此许可证选项子集,请创建一个新变量并利用 cmdlet New-MSOLLicenseOptions:
$LicOpt = New-MsolLicenseOptions -AccountSkuId "yourorg:ENTERPRISEPACK" -DisabledPlans OFFICESUBSCRIPTION,MCOSTANDARD,SHAREPOINTWAC,SHAREPOINTENTERPRISE,RMS_S_ENTERPRISE
(上面的选项与上面的屏幕截图相对应,我相信您可以猜到我完全从配置脚本中提取了它。)
Set-MsolUserLicense最后,我们可以将其与您的 ForEach 循环联系起来:
$LicOpt = New-MsolLicenseOptions -AccountSkuId "yourorg:ENTERPRISEPACK" -DisabledPlans OFFICESUBSCRIPTION,MCOSTANDARD,SHAREPOINTWAC,SHAREPOINTENTERPRISE,RMS_S_ENTERPRISE
Get-ADUser | %{ Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses "yourorg:ENTERPRISEPACK" -LicenseOptions $LicOpt }
Run Code Online (Sandbox Code Playgroud)
与往常一样,您的租户可能会有所不同。我希望我已经为您提供了足够的信息来发现可用的选项并正确应用!
| 归档时间: |
|
| 查看次数: |
2927 次 |
| 最近记录: |