Private/ADLookups/_GetUserLocationAndHostname.ps1
function _GetUserLocationAndHostname { param ( [parameter(Mandatory = $true)] $NameToSearch ) $Object = @() $PossibleUserComputers = @() if ($null -eq $SCCMDevices) { Return "Go to the File menu and click 'Update SCCM Devices'." } else { $PossibleUserComputers += $SCCMDevices | Where-Object CurrentLogonUser -Like "*$NameToSearch*" $PossibleUserComputers += $SCCMDevices | Where-Object PrimaryUser -Like "*$NameToSearch*" if ($null -eq $PossibleUserComputers) { Return 'User not found in SCCM.' } else { foreach ($PossibleUserComputer in $PossibleUserComputers) { $Object += [PSCustomObject] @{ Hostname = $PossibleUserComputer.Name 'Last Active Time' = $PossibleUserComputer.LastActiveTime.ToLocalTime() # SCCM sends the time in UTC 'Current Logon User' = $PossibleUserComputer.CurrentLogonUser 'Primary User' = $PossibleUserComputer.PrimaryUser 'Department' = switch (($PossibleUserComputer.Name).split('-')[0]) { COA { 'Court of Appeals' } SCA { 'Court Administration' } FIS { 'Fiscal Services' } HRM { 'Human Resources' } OIT { 'Information Technology' } ODC { 'Office of Disciplinary Council' } SUP { 'Supreme Court' } CIR { 'Circuit Court' } FAM { 'Family Court' } Default { 'Unknown' } } } } Return $Object } } } |