Powershell Can';连接到office 365时不显示特定属性
因此,我正在编写一个脚本,以自动连接到o365和exchange online,我能够做到这一点,然后脚本将显示特定的属性,出于某种原因,它只选择了一个属性Powershell Can';连接到office 365时不显示特定属性,powershell,office365,select-object,Powershell,Office365,Select Object,因此,我正在编写一个脚本,以自动连接到o365和exchange online,我能够做到这一点,然后脚本将显示特定的属性,出于某种原因,它只选择了一个属性 $getusrname = read-host "what is the user name?" Get-Mailbox -Identity *$getusrname* | ForEach-Object { write-host -ForegroundColor White "I found these users: $_"} | sel
$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
感谢您的帮助首先,您的订单有误,因为
写入主机
只向控制台窗口输出内容,而不向管道发送任何内容
其次,您使用的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
}
非常感谢您的帮助,它确实起作用了,但是对于这样“糟糕的任务”来说,它的行太多了。您能告诉我“-filter”和“-identity”之间的区别吗?行太多了吗?试着把所有的东西都放在一行中是一件坏事,因为正如你所注意到的,这些东西很容易出错,也很难发现<代码>-过滤器可以使用通配符,如
*
。对于-Identity
,您需要准确指定邮箱。我不得不承认,这是有道理的。。我尝试了-anr
,但它“顺便说一句,不起作用。@WebGhost使用-anr
不能使用通配符*
字符。你看过我链接到的官方文件了吗?是的,我的朋友,我有一些拼写错误:)谢谢!