Check out this oneliner/function! Provide a computer name and it will return the logged on users.

function Get-MyLoggedOnUsers
{
 param([string]$Computer)
 Get-WmiObject Win32_LoggedOnUser -ComputerName $Computer | Select Antecedent -Unique | %{“{0}{1}” -f $_.Antecedent.ToString().Split(‘”‘)[1], $_.Antecedent.ToString().Split(‘”‘)[3]}
}

Hugo

No related posts.

  4 Responses to “Oneliner: Get Logged on Users with Powershell”

  1. Would you happen to know how to retrieve the users logged on to a domain?

  2. Thanks Hugo. Glad to know somebody else’s synapses are firing

  3. Hugo,

    your script is almost working :-)

    can only give me the following result:

    Laptop425SYSTEM
    Laptop425LOCAL SERVICE
    Laptop425NETWORK SERVICE
    MYDOMAINusername
    Laptop425ANONYMOUS LOGON

    how to get MYDOMAIN\username only ?

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

   
© 2012 PeetersOnline Suffusion theme by Sayontan Sinha