I'm working on a project where I need to get a friendly name for the local user logged in to a PC. I think I'm 90% there, but I'm missing something. Here is what I have.
$user = whoami /upn
#Get-ADUser -Filter "EmailAddress -eq $user" | Select Name | ft -HideTableHeaders
Get-ADUser -Filter 'EmailAddress -eq "tfox@test.com"' | Select Name | ft -HideTableHeaders
#Test Output
Write-host
Write-host $user
write-host $name
This works great if I feed it a static email address. I cannot for the life of me get it to use the $user variable. I know it's probably a syntax error on my part. Does anyone have any suggestions or a better way to skin a cat?