Powershell script to see currently logged in users (domain and machine) + status (active, idle, away)

后端 未结 6 1401
无人及你
无人及你 2020-11-29 22:44

I am searching for a simple command to see logged on users on server. I know this one :

Get-WmiObject -Class win32_computersystem

but this

6条回答
  •  余生分开走
    2020-11-29 22:48

    If you want to find interactively logged on users, I found a great tip here :https://p0w3rsh3ll.wordpress.com/2012/02/03/get-logged-on-users/ (Win32_ComputerSystem did not help me)

    $explorerprocesses = @(Get-WmiObject -Query "Select * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue)
    If ($explorerprocesses.Count -eq 0)
    {
        "No explorer process found / Nobody interactively logged on"
    }
    Else
    {
        ForEach ($i in $explorerprocesses)
        {
            $Username = $i.GetOwner().User
            $Domain = $i.GetOwner().Domain
            Write-Host "$Domain\$Username logged on since: $($i.ConvertToDateTime($i.CreationDate))"
        }
    }
    

提交回复
热议问题