powershell - 查询 Azure Active Directory 的 UPN 和主 SMTP 地址,然后导出到 CSV

标签 powershell azure active-directory

我正在尝试获取包含两列的 csv:UPN 和主 SMTP 地址。主 SMTP 地址位于 ProxyAddresses 属性中的其他地址中,并且是可识别的,因为 SMTP 全部大写,而次要地址全部小写。

到目前为止,这就是我所拥有的,它返回 ProxyAddresses 列中的所有 SMTP 地址,而不仅仅是带有 SMTP: 前缀的主地址

 $licusers = gc .\licuser_trim.txt
 FOREACH ($user in $licusers)
 {
 Get-MSOLUser -UserPrincipalName $user | Select userprincipalname, Proxyaddresses | ? {$_.ProxyAddresses -cmatch '^SMTP\:.*'} 
 }

最佳答案

删除Proxyaddresses,它会覆盖{$_.ProxyAddresses -cmatch '^SMTP\:.*'}的结果,或更改“|”到“,”。

试试这个:

 Get-MSOLUser -UserPrincipalName $user | Select userprincipalname, @{e={$_.ProxyAddresses -cmatch '^SMTP\:.*'};name='Primaryaddress'},Proxyaddresses

Get-MSOLUser -UserPrincipalName $user| Select Proxyaddresses | select {$_.ProxyAddresses -cmatch '^SMTP\:.*'} 

它将返回由大写“SMTP:”指示的主电子邮件地址。

关于powershell - 查询 Azure Active Directory 的 UPN 和主 SMTP 地址,然后导出到 CSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37422604/

相关文章:

windows - 更新帮助和保存帮助不起作用

powershell - 使用扩展字符串作为 Powershell 函数参数

powershell - 如何使用 PowerShell 获取有关暂存 Windows Azure 网站槽的信息?

c# - 通过 C# 创建帐户时执行 Active Directory 密码策略

通过 Active Directory 2008 进行 Django LDAP 身份验证

c# - 如何使用 C# 读取 "uSNChanged"属性

windows - AppFabric Powershell 新缓存异常

powershell - 如何在同一目录中复制不同名称的文件夹?

Azure 服务总线队列、消息停滞或消息计数不正确?

azure - 公开我的 Azure 服务总线连接字符串是否不安全?