none
Computer name of the other user RRS feed

  • Question

  • I am trying with the below commands to get the computer name of a user but it is not displaying the computer name. Kindly suggest  

    $UserName = Read-Host "Enter the user name"

    Get-ADComputer -Filter {Name -Like "$UserName*"} | Select Name

    Tuesday, August 8, 2017 9:08 AM

Answers

  • Have you tried this way?

    Get-ADComputer -LDAPFilter "(Name=$UserName*)" | Select Name 


    Best regards,
    Pavel Volkov
    MCP, MS: Configuring Windows Devices, Hyper-V and SCVMM
    MCSA: Windows 10/Server 2012/Server 2016/SQL 2016 Database Development;
    MCSE: Mobility, Cloud Platform and Infrastructure

    • Marked as answer by Anbarasu P K Tuesday, August 8, 2017 11:31 AM
    Tuesday, August 8, 2017 10:52 AM

All replies

  • A computer object does not have a "username".  It only has the computer name.  Users do not have computers and computers do not have users.  A user can use a computer.  A computer can be used by a user.

    You can get the currently logged in user using WMI.  You cannot query AD or any other item to find out where a user is logged in.


    \_(ツ)_/


    • Edited by jrv Tuesday, August 8, 2017 10:13 AM
    Tuesday, August 8, 2017 10:13 AM
  • Thank you! We have computer name starts with username. So i have queried with (Name -Like "$UserName*).

    Do you have any suggestion?

    Tuesday, August 8, 2017 10:39 AM
  • I know this is using quest (I much prefer pure powershell ) but you maybe able to modify this for your needs

    https://community.spiceworks.com/scripts/show/1055-find-computers-a-user-is-logged-into

    Tuesday, August 8, 2017 10:44 AM
  • Have you tried this way?

    Get-ADComputer -LDAPFilter "(Name=$UserName*)" | Select Name 


    Best regards,
    Pavel Volkov
    MCP, MS: Configuring Windows Devices, Hyper-V and SCVMM
    MCSA: Windows 10/Server 2012/Server 2016/SQL 2016 Database Development;
    MCSE: Mobility, Cloud Platform and Infrastructure

    • Marked as answer by Anbarasu P K Tuesday, August 8, 2017 11:31 AM
    Tuesday, August 8, 2017 10:52 AM
  • Thank you! We have computer name starts with username. So i have queried with (Name -Like "$UserName*).

    Do you have any suggestion?

    This is the correct way to do what you are trying to do:

    Get-ADComputer -Filter"Name -Like'$UserName*'" | Select Name

    You need double quotes and single quotes.


    \_(ツ)_/

    Tuesday, August 8, 2017 11:14 AM
  • I see what you are doing.  The computer name starts with the user name and you want to retrieve the whole computer name.

    The problem that I ran into when trying this is adding the * in the filter string.

    Try it this way

    $UserName = Read-Host "Enter the user name"

    $Username = $Username + *

    Get-ADComputer -Filter {Name -Like $UserName} | Select Name

    I hope that will help.  It works for me.

    Tuesday, August 8, 2017 2:49 PM