Updated PCMonitor

PCMonitor now prompts for a waiting interval, gives user the option to
be notified, displays a propress bar when initializing sessions, and
updates a datetime so user knows script isn't hanging
This commit is contained in:
Zachary Gorman 2024-07-01 10:32:55 -07:00
parent 2b0c9ed93c
commit a77b048b87

View file

@ -12,20 +12,29 @@ function Invoke-PCMonitor {
$dogs = @() $dogs = @()
# Initialize computer sessions # Initialize computer sessions
foreach ($comp in $comps) { foreach ($comp in $comps) {
Write-Progress -Activity "Initializing sessions" -Status $comp -PercentComplete ($dogs.Length/$comps.Length)
$dog = [WatchDog]::new($comp) $dog = [WatchDog]::new($comp)
$null = $dog.Update() $null = $dog.Update()
$dogs += $dog $dogs += $dog
} }
Write-Progress -Activity "Initializing sessions" -Completed
while ($true) { while ($true) {
$change = $false
foreach ($dog in $dogs) { foreach ($dog in $dogs) {
$msg = $dog.ReportChange() $msg = $dog.ReportChange()
if ($msg) { if ($msg) {
$change = $true
if ($notify) { if ($notify) {
$null = [System.Windows.MessageBox]::Show($msg) $null = [System.Windows.MessageBox]::Show($msg)
} }
Write-Host "$msg" Write-Host "$msg"
} }
} }
# Update date and time so user knows script hasn't frozen
if (-not ($change)) {
$date = Get-Date -Format "[MM/dd/yy HH:mm:ss]"
Write-Host -NoNewline "$date `r"
}
Start-Sleep $sleepTime Start-Sleep $sleepTime
} }
} }