Wmi_NetworkLoginProfile returning empty properties from remote servers

Welcome Forums General PowerShell Q&A Wmi_NetworkLoginProfile returning empty properties from remote servers

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

1 week, 3 days ago.

  • Author
  • #175237

    Topics: 1
    Replies: 0
    Points: 18
    Rank: Member

    I've got a pretty simple query to pull back the last logon date for every account that has logged into a server.  It works great on any server that I remote to and run it on but when I try to feed a list of servers to it, it comes back with empty values for almost all of the properties under the Wmi_NetworkLoginProfile class.  I have domain admin access on the account I'm using and remote is enabled on all the servers.  DCOM looks correct as well.  If I remote to any of the servers in my server list and run it locally, it returns all the values with no issue.  It just won't return them when I run it for a list of all the servers.  I have over 6000 servers that are a variety of Windows versions but all are at least 2008 or later.  Help!  I am relatively new to PowerShell but this seems like it would be a permissions issue but I don't know what other permissions I would need to pull this.  Thanks for the help!!!

    #Set workstation list file (get list of workstations from file)
    $list = Get-Content "C:\Users\A-BLBURKHA\scripts\ServerList.txt"
    #Set Output file
    $OUTPUT = "C:\Users\A-BLBURKHA\scripts\Server_Logged_On_Users.csv"
    #set headers in CSV output file
    echo "ServerName,User,LogonTime" | Out-File -FilePath $OUTPUT
    #begin script logic
    $list | ForEach-Object {
    echo "Current computer $_"
    #Test if system is online
    Invoke-Expression "ping -n 1 -w 500 $_" | Out-Null
    $ping = $LASTEXITCODE
    #If Pingable perform the following collection actions
    if (!$ping){
    #Retrieve listings of ALL users that have logged on to the server and send results to Output File
    $NetLogs = Get-WmiObject Win32_NetworkLoginProfile -ComputerName $_
    foreach ($NetLog in $NetLogs) {
    if ($NetLog.UserType -eq "Normal Account" -AND $NetLog.LastLogon -match "(\d{14})") {
    $row = "" | Select Name,LogonTime
    $row.Name = $NetLog.Name
    $row.LogonTime=[datetime]::ParseExact($matches[0], "yyyyMMddHHmmss", $null)
    foreach ($RName in $row) {
    $Name = $row.Name
    $LTime = $row.LogonTime
    #Write "ServerName, Name, and TimeStamp" results to Output File
    echo "$_,$Name,$LTime" >> $OUTPUT }
    } else {
    #If System is not pingable, the System Name is written to the NotPingable.csv file
    echo "$_ not pingable"
    echo "$_" >> NotPingable.csv
  • #175285

    Topics: 1
    Replies: 1528
    Points: 2,581
    Helping Hand
    Rank: Community Hero

    Your code is quiet ... hmmm ... let's say immature ... 😉

    You may start to write pure Powershell code and get rid of aliasses and external tools like ping. Powershell can do better. 😉

    Start with something like this and extend it to your needs

    $ServerList = Get-Content "C:\Users\A-BLBURKHA\scripts\ServerList.txt"
    Foreach ($ComputerName in $ServerList) {
        If (Test-Connection -ComputerName $ComputerName -Count 1 -Quiet) {
            Get-CimInstance -ClassName Win32_NetworkLoginProfile -ComputerName $ComputerName |
            Where-Object { $_.UserType -eq 'Normal Account' } |
            ForEach-Object {
                    ComputerName = $ComputerName
                    Name         = $_.Caption
                    LastLogon    = $_.LastLogon

    Of course you can pipe the results to CSV file or save it to a variable to use it for further steps in code.

You must be logged in to reply to this topic.