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

请求调整PowerShell脚本:筛选美加AzureAD用户并替换字段

调整后的AzureAD用户导出PowerShell脚本

脚本代码

# 检查并安装AzureAD模块(首次运行需要)
if (-not (Get-Module -ListAvailable -Name AzureAD)) {
    Install-Module -Name AzureAD -Force -AllowClobber
}
Import-Module AzureAD

# 连接到Azure Active Directory
Connect-AzureAD

# 筛选美国/加拿大用户,替换License字段为City并导出到CSV
Get-AzureADUser -Filter "Country eq 'United States' or Country eq 'Canada'" |
    Select-Object DisplayName,
                  UserPrincipalName,
                  City,
                  Country,
                  Department,
                  JobTitle | # 可根据需求增减字段
    Export-Csv -Path ".\AzureAD_US_CA_Users.csv" -NoTypeInformation -Encoding UTF8

关键调整说明

  • 区域筛选:通过-Filter参数使用OData语法精准筛选国家或地区为美国(United States)或加拿大(Canada)的用户。如果你的AzureAD中存储的是国家缩写(比如"US"、"CA"),直接把筛选条件改成"Country eq 'US' or Country eq 'CA'"即可。
  • 字段替换:移除原脚本中与License相关的字段,在Select-Object中加入City字段,你可以根据实际需求添加或删除其他需要导出的用户属性(比如Mail、Mobile等)。
  • 导出优化:指定-Encoding UTF8避免CSV出现乱码,-NoTypeInformation去掉文件开头的多余类型声明行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 14:07:06