powershell - 连接到 Office 365 时无法显示特定属性
问题描述
所以我正在编写一个脚本来自动连接到 o365 并在线交换,我能够做到这一点,然后脚本配偶向我展示特定的属性,并且由于某种原因它只选择了一个属性
$getusrname = read-host "what is the user name?"
Get-Mailbox -Identity *$getusrname* | ForEach-Object { write-host -ForegroundColor White "I found these users: $_"} | select name, @{n="Email adress";e='UserPrincipalName'}
我得到这个输出:
I found these users: Lev Leiderman
谢谢你的帮助
解决方案
首先是您的顺序错误,因为write-host
仅将内容输出到控制台窗口而没有发送任何内容到管道。
其次,UserPrincipalName
您使用的并不总是与用户完全相同PrimarySmtpAddress
(可能是,但并非总是如此)
我认为这会让你更进一步:
$getusrname = Read-Host "what is the user name?"
# instead of using a Filter, you can also experiment with the '-Anr' parameter
# to perform an ambiguous name resolution (ANR) search.
# See: https://docs.microsoft.com/en-us/powershell/module/exchange/mailboxes/get-mailbox?view=exchange-ps#parameters
$users = Get-Mailbox -Filter "Name -like '*$getusrname*'" |
Select-Object Name, @{Name = "Email adress"; Expression = 'PrimarySmtpAddress'}
if ($users) {
Write-Host "I found these user(s):"
$users | Format-Table -AutoSize
}
else {
Write-Host "No user found for $getusrname" -ForegroundColor Red
}
推荐阅读
- javascript - Webpack 正在向捆绑文件添加额外的代码(导致它在包含后抛出错误)
- hibernate - 是否有不被擦除的属性的实体约束注释
- c# - Azure 事件中心 - 按顺序接收事件
- c++ - 这个功能有什么问题?它没有显示错误,但一直输出为 0
- node.js - VSCode 调试(F5)react app 给出 SyntaxError: Unexpected identifier
- python - 使用 os.path.isfile 和 'and' 语句检查 2 个文件是否存在
- javascript - Angular JS 使用 trustasHtml 将字符串呈现为 html 显示错误
- xquery - 如果我不知道属性的值,如何在 Marklogic 数据库的任何文档中搜索属性的出现?
- javascript - 条件下拉在 IE 中不起作用
- c# - 从特定格式的字符串中获取时间