Avatar of MilesLogan
MilesLoganFlag for United States of America

asked on 

Get logged on user for multiple machines with Poweshell

Hi EE

Does anyone have a script that I can use for this ? I used the script the below to check the the UserProfile time and filtered by today's
date .. but I am getting mixed results .. so not sure if this is accurate .. wondering what every one is using ?

Get-WmiObject -ComputerName (get-content C:\PS\Machines.txt) Win32_UserProfile | % {
  $userinfo = [WMI] ($_.__Path -Replace "Win32_UserProfile", "Win32_SID")
  New-Object PsObject -Property @{
    ComputerName= $_.__Server
    Domain      = $userinfo.ReferencedDomainName
    User        = $userinfo.AccountName
    LastUsed    = $_.ConvertToDatetime($_.LastUseTime)
  }
} | export-csv -NoType C:\PS\test_Data.csv

Open in new window

Powershell

Avatar of undefined
Last Comment
MilesLogan
Avatar of MilesLogan
MilesLogan
Flag of United States of America image

ASKER

I tried this and it does return the logged on user but I cant get it to output the PSComputerName or CSNAme value .. so the csv file can have one column with the user and the other with the corresponding machine name

Get-WmiObject Win32_Process -ComputerName MachineName | Where {$_.name -eq 'explorer.exe'}| Invoke-WmiMethod -name GetOwner | select user

Open in new window


heeeeelp
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of MilesLogan
MilesLogan
Flag of United States of America image

ASKER

Thanks oBdA ! .. worked realy well
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo