# Local Logged In User

**URL:** <https://forums.powershell.org/t/local-logged-in-user/4560>\
**Category:** PowerShell Help\
**Created:** [July 23, 2015, 4:19am UTC](https://forums.powershell.org/t/local-logged-in-user/4560 "2015-07-23T04:19:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tim-fox](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tim-fox/32/760_2.png) [@tim-fox](https://forums.powershell.org/u/tim-fox)\
**Post date:** [July 23, 2015, 4:19am UTC](https://forums.powershell.org/t/local-logged-in-user/4560/1 "2015-07-23T04:19:31Z")

</div>

I’m trying to come up with a way to get a display or friendly name for a local user logged into their PC. This is part of a larger project, and I need to be able to write some basic information to a database.

Here’s what I have so far. I cannot for the life of me figure out what I am doing wrong. I am assuming it is a syntax error, as it works when I feed it information rather than a variable.

$user = whoami /upn  
#Get-ADUser -Filter ‘EmailAddress -eq “$user”’ | Select Name | ft -HideTableHeaders  
Get-ADUser -Filter ‘EmailAddress -eq “[tfox@test.com](mailto:tfox@test.com)”’ | Select Name | ft -HideTableHeaders

#Test Output  
Write-host  
Write-host $user  
write-host $name

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [July 23, 2015, 4:27am UTC](https://forums.powershell.org/t/local-logged-in-user/4560/2 "2015-07-23T04:27:07Z")

</div>

The outermost set of quotation marks determine whether PowerShell replaces variables or not. In your example, they’re single quotes, so $user is being passed literally rather than being replaced.

---

<div class="post-metadata">

**Author:** ![tim-fox](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tim-fox/32/760_2.png) [@tim-fox](https://forums.powershell.org/u/tim-fox)\
**Post date:** [July 23, 2015, 4:35am UTC](https://forums.powershell.org/t/local-logged-in-user/4560/3 "2015-07-23T04:35:07Z")

</div>

Thanks, that gets me further along.

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [July 23, 2015, 4:58am UTC](https://forums.powershell.org/t/local-logged-in-user/4560/4 "2015-07-23T04:58:36Z")

</div>

In VBScript, there was a COM object called ADSystemInfo that was an easy way to get AD information for the logged on user. Check this out as a Powershell way:

[https://technet.microsoft.com/en-us/library/ff730963.aspx](https://technet.microsoft.com/en-us/library/ff730963.aspx)

Keep in mind that if this is running on the client, that Windows RSAT tools need to be installed in order to use Get-ADUser as you will need the ActiveDirectory module. So, typically, ADSI is leveraged to find user information in those instances which is provided I the above link. The ADSI there can be shortened a bit, but validate it is working as expected first.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:45pm UTC](https://forums.powershell.org/t/local-logged-in-user/4560/5 "2024-05-16T20:45:00Z")

</div>


