Workflow, Get-lastlogged on User foreach Computer in the company

Welcome Forums General PowerShell Q&A Workflow, Get-lastlogged on User foreach Computer in the company

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 4 months ago.

  • Author
  • #78923

    Points: 1
    Rank: Member

    Hi everyone

    I am a newbie in powershell, so my code is not perfect.

    I am creating a script where I get the last logged on User on every computer in the company. It works, but it is slow. I saw the Worflow cmdlet and tried with this one, but it only returns 8 PCs and not all. Does someone have an idea?


    function Get-LastLoggedOnUser($computerName)
        Get-WmiObject Win32_NetworkLoginProfile -Computer $computerName |
        Sort -Descending LastLogon |
        Select * -First 1 |
        ? {$_.LastLogon -match "(\d{14})"} |
            % {
                New-Object PSObject -Property @{
                    computername = $computerName
    workflow Get-LastLoggedUseronPC
        $userList = @()
        foreach -parallel ($computer in $computerList)
            if (-not (Test-Connection -ComputerName $computer.DNSHostName -Quiet -count 1)){}
                $WORKFLOW:userList += Get-LastLoggedOnUser -computerName $computer.Name
    $computerList = Get-ADComputer -Filter{name -like "*"}| where {$ -le 8}
    PS C:\WINDOWS\system32>$userList
    computername Name
    ------------ ----
    PC100001     PC100001\MyUser
    PC100002     PC100002\otherUser
    PC100003     PC100003\anotherUser
    .            .
    .            .
    .            .
    PC100008     PC100008\testuser
  • #78928

    Points: 0
    Rank: Member

    You can try this command:

    $MachineList = Get-Content -Path c:\ListOfMachines.txt; # One system name per line
    foreach ($Machine in $MachineList){
    ($Machine + ": " + @(Get-WmiObject -ComputerName $Machine -Namespace root\cimv2 -Class Win32_ComputerSystem)[0].UserName);

    Here are related articles for help.

  • #78931

    Points: 1
    Rank: Member

    Sorry, I was unclear about my result I want to achieve.
    I would like to get the last Computer where a User was logged on. The time when it happend is clear.
    So my plan is to get all PC last logged on user and then select the PC where the specific user was logged on.

The topic ‘Workflow, Get-lastlogged on User foreach Computer in the company’ is closed to new replies.