Is it possible to pipe in a list of usernames to SCCM and have it pump out the machine they last logged onto? I thought the get-CMUserDeviceAffinity would do it but it appears it won't take the username and give me a machine name.
Thanks
alex
PowershellSCCM
Last Comment
Alex
8/22/2022 - Mon
Michael Pfister
This takes a simple text file with user names c:\Temp\user.txt and shows a list of computers they were logged on (LastLogonUser)
HTH
$SiteCode = "XXX" # Site code $ProviderMachineName = "sccmserver"$initParams = @{}#$initParams.Add("Verbose", $true) # Uncomment this line to enable verbose logging#$initParams.Add("ErrorAction", "Stop") # Uncomment this line to stop the script on any errorsif((Get-Module ConfigurationManager) -eq $null) { Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" @initParams }if((Get-PSDrive -Name $SiteCode -PSProvider CMSite -ErrorAction SilentlyContinue) -eq $null) { New-PSDrive -Name $SiteCode -PSProvider CMSite -Root $ProviderMachineName @initParams}Set-Location "$($SiteCode):\" @initParamsGet-Content c:\Temp\user.txt | % {$Username = $_ $Devices = Get-CMDevice | Where {$_.LastLogonUser -eq "$UserName"} $Devices | Select Name,LastLogonUser }
HTH
Open in new window