I am working on something to retrieve account information from a domain controller.
$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'
So if the account is in server.com I receive as output the UPN of that account, but if the account is not in server.com I want to receive 'No corresponding UPN' but instead receiving that output it's empty.
Any idea?
Thanks in advance.
Kind Regards, Ralph