【发布时间】:2020-04-08 10:21:35
【问题描述】:
我正在做一些事情来从域控制器中检索帐户信息。
$Input = $InputBox1.Text
$InputBox10.Text = (Get-ADUser -Filter "UserPrincipalName -like '$Input'" -Server "server.com" -Properties UserPrincipalName | Select-Object @{Name='UPN'; Expression={if($Input -ne $_.UserPrincipalName){'No corresponding UPN'}else{$_.UserPrincipalName}}}).'UPN'
因此,如果该帐户在 server.com 中,我会收到该帐户的 UPN 作为输出,但如果该帐户不在 server.com 中,我希望接收“没有相应的 UPN”,而是接收该输出,它是空的。
有什么想法吗?
提前致谢。
亲切的问候, 拉尔夫
【问题讨论】:
-
顺便说一句,不要使用
$Input作为自定义变量名,因为它是一个Automatic variable -
除了 Theo 的注释,这是否回答了您的问题? Why won't Variable update?
标签: powershell