Solved

PowerShell: How to determine who is logged onto a remote Windows System

Posted on 2010-09-10
5
1,046 Views
Last Modified: 2012-05-10
I need some code to help me determine who is logged into a remote computer.

Specially, who is logged onto a Window 7 and/or Windows 2008 system. (Since multiple people can be logged on...)

I'm using this code now, and it pretty much shows me as logged onto a bunch of stuff... that I'm fairly certain I'm not logged into.  (So I suspect it's showing the credentials I'm using to run the script.)

$serverlist = [collections.arraylist] (@(Get-QADComputer -OSName 'Windows*Server*' | Select-Object -ExpandProperty name) | %{$_} | Sort-Object)

ForEach($Server in $serverlist)  

{Gwmi Win32_Computersystem -Comp $Server | Select Name, UserName}

I'm specifically interested to know if there is a way to determine multiple logons to one system.
0
Comment
Question by:gerhardub
  • 2
  • 2
5 Comments
 
LVL 20

Expert Comment

by:Lazarus
ID: 33649195
0
 
LVL 1

Author Comment

by:gerhardub
ID: 33649590
That doesn't appear to work, and if the function does, it's not working for me.
0
 
LVL 1

Author Comment

by:gerhardub
ID: 33649595
Is there anything that is not WMI that could be useful?
0
 
LVL 20

Expert Comment

by:Lazarus
ID: 33649742
Not that I know of, but there might be.
0
 
LVL 13

Accepted Solution

by:
soostibi earned 500 total points
ID: 33653924
This gives all interactive and terminal logons. Unfortunately I am not able to run it remotly using the remoting of WMI, only by the remoting of PowerShell.
Get-WmiObject -Class win32_logonsession -Filter "LogonType = 2 OR LogonType = 10"  | 
    %{ get-wmiobject -Query "Associators of {Win32_logonSession.LogonID=$($_.LogonId)} where AssocClass = Win32_LoggedOnUser Role=Dependent" }

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A safe way to clean winsxs folder from your windows server 2008 R2 editions
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question