none
Looking for Script to get Computer names from list of users, Powershell newbie RRS feed

  • Question

  • Hi Everyone:

    I am a PowerShell newbie, only know few one line PowerShell. Now I am looking for help to use PowerShell script to get Computer name from a list (.txt) of user name. hope you guys can help out here.

    Thanks very much 


    yan

    • Moved by Bill_Stewart Wednesday, September 4, 2019 7:55 PM This is not "scripts on demand"
    Friday, April 5, 2019 3:54 PM

All replies

  • Computer names are not assigned to users in any way.  There is no command that can do this.

    You can get the current logged in user with PS but you cannot find a computer by user name.  To do this you would need to have a list of assigned computers to begin with.

    The issue is not about PowerShell or scripting but is one of fundamental Windows technical training.


    \_(ツ)_/


    • Edited by jrv Friday, April 5, 2019 4:17 PM
    Friday, April 5, 2019 4:16 PM
  • Great to learn that, thanks Jrv.

    I guess I need change my question, I able to get  "Last login user" with list of computer name in SCCM.

    so, is there anyway I can get computer names with list of "Last login user" in PowerShell?


    yan

    Friday, April 5, 2019 4:56 PM
  • For SCCM issues you need to post  the SCCM forum.

    If you already have a list of users and computers why would you need to do this?

    Since any user can log I to any computer the value of this is in question.


    \_(ツ)_/

    Friday, April 5, 2019 4:59 PM
  • Problem is as business need, I got the list of users (over hundred) from all different group random, they want to install some software to their computer for testing, Now I am able to find the computer from our AD login logs one by one, but there are over hundreds users, that is why I am looking for a PowerShell which can help to pull the computer names from a list of "last login user". will save me time on this task also learn what I can get.

    yan

    Friday, April 5, 2019 5:49 PM
  • Cn you post the script you have tried to use?  The forum is not here to write scripts for you.

    What have you tried?


    \_(ツ)_/

    Friday, April 5, 2019 7:13 PM
  • # Get device(s) by primary user
    Get-CMUserDeviceAffinity -UserName DOMAIN\UserName | select ResourceName
    
    # Get device(s) by last logged on user
    Get-CMDevice | where LastLogonUser -eq 'UserName' | select Name

    Have you looked at the Configuration Manager cmdlets?

    Get started with Configuration Manager cmdlets

    Configuration Manager PowerShell

    You can also query a SCCM server using WMI.

    SMS_R_System Server WMI Class

    $SiteCode = 'ABC'
    $CMServer = 'CMServer'
    $UserName = 'UserName'
    $WMIQuery = "SELECT Name FROM SMS_R_System WHERE LastLogonUserName = '$UserName'"
    
    $Request = @{
        NameSpace    = "root\SMS\site_$SiteCode"
        ComputerName = $CMServer
        Query        = $WMIQuery
    }
    
    Get-WmiObject @Request | select Name



    Saturday, April 6, 2019 10:40 AM