Powershell Script Running Result Log Viewer

I have lots of scheduled PowerShell script running regularly. This code will show all the Powershell running result log via webpage online.

# Powershell Script Running Log Viewer
# Rui Qiu
# 9/3/2021

$Session:value = "SCCM-backup.log"

# Selector to choose the log
New-UDSingleSelector -Id "list"  -options {
	@{ value = "SCCM-backup.log"; label = "SCCM Site Backup" },
	@{ value = "awsday1.log"; label = "Internal Workspace Day 1" },
	@{ value = "awsday2.log"; label = "Internal Workspace Day 2" },
	@{ value = "awsreboot.log"; label = "Internal Workspace Reboot" },
	@{ value = "externaL.log"; label = "External Workspace" }
    @{ value = "externalreboot.log"; label = "External Workspace Reboot" }
    @{ value = "serverreboot.log"; label = "Server Reboot" }
}

# One line for spacing
New-UDElement -tag 'div' -attributes @{
    style = @{ 
        height = '10px'
        }
}  

# Button to get the result
New-UDButton -Text "Get Report" -OnClick {
	$UDElement = Get-UDElement -id "list"
	$Session:value=$UDElement.Attributes.selectedOption.value
	Show-UDToast -Message "You have selected $Session:value" -Duration 5000
	Sync-UDElement -Id 'list' 
}

# Display the result
New-UDDynamic -Id 'list' -Content {
    $path = "\\xxx\C$\Temp\$Session:value"
    $result = "<font face='monospace'>$(Get-Content $path | ForEach-Object {"$($_ -replace '\s',' ') <br/>"})</font>"
    New-UDCard -Title 'Results' -Content {
            New-UDHtml -Markup $result
        }
}

Leave a Comment