Online SCCM Client Log Viewer

This is one of my favorite code to run client log viewer online in an interactive way. Instead of use the CMTrace to see the client log, going through all the hoops, you can just type in client name and log type to view the data online.

# SCCM Client Log Viewer
# Rui Qiu
# 9/3/2021

#Log Format Reference
#https://gist.github.com/RichPrescott/cf2225ca6435de20dffbbb120234e1fb#file-get-cmlog-ps1

# Textbox and Selector to get machine name and log type
New-UDTextbox -Id 'pc' -Placeholder 'Machine Name'
New-UDElement -tag 'div' -attributes @{
    style = @{ 
        height = '10px'
    }
}
New-UDSingleSelector -Id "list"  -options {
	@{ value = "AppEnforce.log"; label = "Application Deployment" },
	@{ value = "AppDiscovery.log"; label = "Application Detection" },
	@{ value = "UpdatesDeployment.log"; label = "Patching Deployment" },
	@{ value = "WUAHandler.log"; label = "WSUS Agent Health" },
	@{ value = "DataTransferService.log"; label = "Data Transfer Service" },
    @{ value = "ClientLocation.log"; label = "Client Location" },
    @{ value = "LocationServices.log"; label = "Location Service" },
    @{ value = "smsts.log"; label = "Task Sequence" }
}

New-UDElement -tag 'div' -attributes @{
    style = @{ 
        height = '10px'
    }
}
New-UDButton -OnClick {
	$UDElement = Get-UDElement -id "list"
	$session:list=$UDElement.Attributes.selectedOption.value
    $session:pc = (Get-UDElement -Id 'pc').value
    Show-UDToast -Message "You have selected $session:list on $session:pc, it will take a few minutes to get the result." -Duration 5000
    Sync-UDElement -Id 'table'
} -Text "Confirm" 

New-UDElement -tag 'div' -attributes @{
    style = @{ 
        height = '10px'
    }
}

# Get the client data and form the table to show data
New-UDDynamic -Id 'table' -Content {
    $path = "\\$session:pc\C$\Windows\CCM\logs\$Session:list"
    $result = "<font face='monospace'>$(Get-Content $path -Raw | ForEach-Object { $_ -replace '<!\[LOG\[', '' } | ForEach-Object { $_ -replace '\]LOG\]!>(.*)', '<br/>' })</font>"
    $data = Get-Content -Path $path | %{
                $_ -match '\<\!\[LOG\[(?<Message>.*)?\]LOG\]\!\>\<time=\"(?<Time>.+)(?<TZAdjust>[+|-])(?<TZOffset>\d{2,3})\"\s+date=\"(?<Date>.+)?\"\s+component=\"(?<Component>.+)?\"\s+context="(?<Context>.*)?\"\s+type=\"(?<Type>\d)?\"\s+thread=\"(?<TID>\d+)?\"\s+file=\"(?<Reference>.+)?\"\>' | Out-Null
                [pscustomobject]@{
                    UTCTime = [datetime]::ParseExact($("$($matches.date) $($matches.time)$($matches.TZAdjust)$($matches.TZOffset/60)"),"MM-dd-yyyy HH:mm:ss.fffz", $null, "AdjustToUniversal")
                    LocalTime = [datetime]::ParseExact($("$($matches.date) $($matches.time)"),"MM-dd-yyyy HH:mm:ss.fff", $null)
                    Message = $matches.message
                }
            }

    New-UDTable -Data $data -Title "Detailed logs" -ShowSort -Dense -Export -DefaultSortDirection Descending
    }
    

1 thought on “Online SCCM Client Log Viewer”

Leave a Comment