You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改PowerShell脚本仅输出匹配指定Azure AD许可证的用户

修改后可实现筛选功能的完整脚本

Connect-MsolService

# 定义要筛选的目标许可证SKU,调整筛选规则时只需修改该变量值即可
$targetLicense = "testdomain:SPE_E3"
$Users= Import-CSV C:\Users\Ark\Desktop\powershell\test01.csv

$Users | ForEach-Object {
    Get-MsolUser -UserPrincipalName $_.UPN | 
    Select-Object UserPrincipalName, @{n="Licenses Type";e={$_.Licenses.AccountSKUid}} |
    # 过滤规则:匹配持有目标许可证的用户,兼容单个用户持有多个许可证的场景
    Where-Object { $_."Licenses Type" -contains $targetLicense }
}

说明

  • 如果确认所有用户最多只会分配1个许可证,可将过滤条件替换为$_."Licenses Type" -eq $targetLicense,运行效果完全一致

注意:如果你的CSV文件实际表头为UserPrincipalName而非UPN,需要把脚本里的$_.UPN替换为$_.UserPrincipalName

内容的提问来源于stack exchange,提问作者coderific

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 00:45:05