Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

SOLVED Find user name and computer name in SCCM

Dineshyadav

Well-Known Member
Messages
46
Reaction score
0
Points
8
I have a question. When inside of the Configuration manager and looking at a collection I don't know what the users computer is because it doesn't show a name associated with the computer. Is there a way to display the computer name and the user's name on the same screen so I can remote to it?. I want to get the user name and computer in sccm.
 
Hi Dinesh,
You can use powershell scirpt on sccm , so you can view user nae and computer at a same time... Use the below script... To before use, test script in test domain

Following script to query SCCM for the “list of computer’s who’s last logged on user” is the person I am looking for.

FUNCTION JBMURPHY-SCCM-GetComputerByLastLoggedOnUser {
Param([parameter(Mandatory = $true)]$SamAccountName,
$SiteName="JBM",
$SCCMServer="SCCMServer.domain.local")
$SCCMNameSpace="root\sms\site_$SiteName"
Get-WmiObject -namespace $SCCMNameSpace -computer $SCCMServer -query "select Name from sms_r_system where LastLogonUserName='$SamAccountName'" | select Name
}
 
Hi, one of colleague working with me installed the right click tools on sccm server. When right click on the user name I can get the computer name used by the user. So this is sufficient for me.
 
Hi Dinesh,
You can use powershell scirpt on sccm , so you can view user nae and computer at a same time... Use the below script... To before use, test script in test domain

Following script to query SCCM for the “list of computer’s who’s last logged on user” is the person I am looking for.

FUNCTION JBMURPHY-SCCM-GetComputerByLastLoggedOnUser {
Param([parameter(Mandatory = $true)]$SamAccountName,
$SiteName="JBM",
$SCCMServer="SCCMServer.domain.local")
$SCCMNameSpace="root\sms\site_$SiteName"
Get-WmiObject -namespace $SCCMNameSpace -computer $SCCMServer -query "select Name from sms_r_system where LastLogonUserName='$SamAccountName'" | select Name
}
Hi Maunil, Thanks first for this script it is really useful, the only issue I do have it is going by one user input to give you the result for what machine(s) he/she logged in to it. my question close to this script which is what I need to add to it to let the script put csv file with username on it. for example :
add Import-Csv -Path "C:\test.csv" what else I need to add my see name column is "samaccountname". Please advice
 
You should do all of this within SQL not use WQL and the CM provider. it add a lot of load to the server.
 
Have you looked at the built-in reports? What EXACTLY is your goal?
My goal is to provide the script with csv file when "SamAccountName" is users' names and let the script give me the devices these user are logged in and last time they logged in to it just in case they logged in to many devices . The scrip above is working fine to provide only one user each time and not the date and time they logged into look at the ghange I did and tell me what is wrong or need to add toit:-

Clear-houst
$AccountName =Import-csv -path "c:\test.csv" | slect-object -Expandproperty SamAccountName
foreach ($AccountName in $accountNames)
{JBMURPHY-SCCM.com-GetComputerByLastLoggedonUser -SamAccountName $accountNames}
{
Param([parameter(Mandatory = $true)]$SamAccountName,
$SiteName="JBM",
$SCCMServer="SCCMServer.domain.local")
$SCCMNameSpace="root\sms\site_$SiteName"
Get-WmiObject -namespace $SCCMNameSpace -computer $SCCMServer -query "select Name from sms_r_system where LastLogonUserName='$SamAccountName'" | Select-Object Name
}
 
I'm going to tell you to use the built-in report for this. This will be less stress on your CM environment.
 
And I should also say that you can use the export feature to get the result as Excel or CSV.
 
Back
Top