From 49750da7a5bf19784e54050addff50dfcfb598a8 Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Mon, 14 Apr 2025 11:28:50 -0700 Subject: [PATCH] Small fixes --- Get-PC/Data/AppsToIgnore.json | 3 +++ Get-PC/Private/Get-CMDBFallback.ps1 | 2 +- Get-PC/Private/Get-Hostname.ps1 | 27 ++++++++++++++------------- Get-PC/Private/PCMonitor.ps1 | 3 ++- Get-PC/Private/SHSPrinter.ps1 | 10 ++++------ Get-PC/Private/UninstallProgram.ps1 | 2 +- Get-PC/patchnotes.txt | 5 +++++ 7 files changed, 30 insertions(+), 22 deletions(-) diff --git a/Get-PC/Data/AppsToIgnore.json b/Get-PC/Data/AppsToIgnore.json index 155f67d..2272ee8 100644 --- a/Get-PC/Data/AppsToIgnore.json +++ b/Get-PC/Data/AppsToIgnore.json @@ -40,5 +40,8 @@ }, { "DisplayName": "Maxx Audio Installer" + }, + { + "DisplayName": "Visage 7.1 (64 bit)" } ] \ No newline at end of file diff --git a/Get-PC/Private/Get-CMDBFallback.ps1 b/Get-PC/Private/Get-CMDBFallback.ps1 index 6e48538..cb74af4 100644 --- a/Get-PC/Private/Get-CMDBFallback.ps1 +++ b/Get-PC/Private/Get-CMDBFallback.ps1 @@ -18,7 +18,7 @@ function Get-CMDBFallback { if($cmdbData){ $comp = $cmdbData.Name Write-Progress -Activity "CMDB Fallback $comp" -Status "Asset tag found, checking connection to $comp" -PercentComplete 70 -ParentId 1 - if(Test-Connection $comp){ + if(Test-Connection $comp -Count 1){ Write-Progress -Activity "CMDB Fallback $comp" -Status "Rerunning get-pc with new name $comp" -PercentComplete 85 -ParentId 1 $getpcData = get-pc $comp Write-Progress -Activity "CMDB Fallback $comp" -Completed diff --git a/Get-PC/Private/Get-Hostname.ps1 b/Get-PC/Private/Get-Hostname.ps1 index 20c316b..c25febb 100644 --- a/Get-PC/Private/Get-Hostname.ps1 +++ b/Get-PC/Private/Get-Hostname.ps1 @@ -1,11 +1,23 @@ function Get-Hostname ([string]$name) { - Write-Progress -Activity "Resolving hostname for $name" -PercentComplete 0 -ParentId 1 + # IP address matching goes first so the next check doesn't short and return back the IP + Write-Progress -Activity "Resolving hostname for $name" -Status 'IP Address resolution' -PercentComplete 0 -ParentId 1 + # Regex to match IP Address brought to you by https://stackoverflow.com/a/36760050 + if ($name -match "^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$") { + $res = Resolve-DnsName $name + if ($res -and $res.NameHost -and ($res.NameHost -match "([^.]+)(\.[^.]+)?\.int\.samhealth\.net")) { + Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1 + return $Matches[1],'' + } else { + $errMsg += "IP Address couldn't be resolved to hostname`n" + } + } + Write-Progress -Activity "Resolving hostname for $name" -PercentComplete 10 -ParentId 1 # Return early if the hostname already resolves if (Resolve-DnsName $name) { Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1 return $name,'' } - Write-Progress -Activity "Resolving hostname for $name" -Status 'SCCM Asset Tag Lookup' -PercentComplete 10 -ParentId 1 + Write-Progress -Activity "Resolving hostname for $name" -Status 'SCCM Asset Tag Lookup' -PercentComplete 20 -ParentId 1 $errMsg = '' if ($name.Length -eq 5) { $res = Get-AssetConversion $name @@ -16,17 +28,6 @@ function Get-Hostname ([string]$name) { # We don't check CMDB asset tags here because they often resolve to # something other than the hostname, like the asset tag itself } - Write-Progress -Activity "Resolving hostname for $name" -Status 'IP Address resolution' -PercentComplete 20 -ParentId 1 - # Regex to match IP Address brought to you by https://stackoverflow.com/a/36760050 - if ($name -match "^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$") { - $res = Resolve-DnsName $name - if ($res -and $res.NameHost -and ($res.NameHost -match "([^.]*)\.int\.samhealth\.net")) { - Write-Progress -Activity "Resolving hostname for $name" -Completed -ParentId 1 - return $Matches[0],'' - } else { - $errMsg += "IP Address couldn't be resolved to hostname`n" - } - } Write-Progress -Activity "Resolving hostname for $name" -Status 'SCCM Serial Number lookup' -PercentComplete 30 -ParentId 1 if ($name.Length -eq 7) { $res = Get-ServiceTagConversion $name diff --git a/Get-PC/Private/PCMonitor.ps1 b/Get-PC/Private/PCMonitor.ps1 index ba32eac..e87bb5e 100644 --- a/Get-PC/Private/PCMonitor.ps1 +++ b/Get-PC/Private/PCMonitor.ps1 @@ -14,7 +14,8 @@ function Invoke-PCMonitor { foreach ($comp in $comps) { Write-Progress -Activity "Initializing sessions" -Status $comp -PercentComplete ($dogs.Length/$comps.Length) $dog = [WatchDog]::new($comp) - Write-Output $dog.ReportChange() + $null = $dog.Update() + Write-Output $dog $dogs += $dog } Write-Progress -Activity "Initializing sessions" -Completed diff --git a/Get-PC/Private/SHSPrinter.ps1 b/Get-PC/Private/SHSPrinter.ps1 index ce84159..d659748 100644 --- a/Get-PC/Private/SHSPrinter.ps1 +++ b/Get-PC/Private/SHSPrinter.ps1 @@ -29,12 +29,10 @@ $Headers = @{ $domains = @('.gsrmc.int.samhealth.net','.avery.int.samhealth.net','.sagh.int.samhealth.net','.snlh.int.samhealth.net','.slch.int.samhealth.net','.spch.int.samhealth.net') $result = Resolve-DnsName $printer -ErrorAction SilentlyContinue - if($null -eq $result){ - foreach ($domain in $domains) { - $search = "$printer$domain" - $result = Resolve-DnsName $search -ErrorAction SilentlyContinue - if($null -ne $result){ break } - } + foreach ($domain in $domains) { + if($null -ne $result){ break } + $search = "$printer$domain" + $result = Resolve-DnsName $search -ErrorAction SilentlyContinue } #CMDB Data diff --git a/Get-PC/Private/UninstallProgram.ps1 b/Get-PC/Private/UninstallProgram.ps1 index b97485c..762953a 100644 --- a/Get-PC/Private/UninstallProgram.ps1 +++ b/Get-PC/Private/UninstallProgram.ps1 @@ -31,7 +31,7 @@ function Invoke-UninstallProgram ($Computer) { 1641 { Write-Host "Successfully Uninstalled $($apps[$item].Name) from $Computer"; Write-Warning "Restarting $Computer" } 3010 { Write-Host "Successfully Uninstalled $($apps[$item].Name) from $Computer"; Write-Warning "Please restart $Computer to finish uninstall" } 3011 { Write-Host "Successfully Uninstalled $($apps[$item].Name) from $Computer"; Write-Warning "Please restart $Computer to finish uninstall" } - default { Write-Warning "$appname failed to uninstall from $Computer with ReturnValue $($res.ReturnValue)" } + default { Write-Warning "$appname failed to uninstall from $Computer with ReturnValue $($res.ReturnValue). See an MsiExec return value table for more information." } } } } diff --git a/Get-PC/patchnotes.txt b/Get-PC/patchnotes.txt index 0f9fa93..c56d397 100644 --- a/Get-PC/patchnotes.txt +++ b/Get-PC/patchnotes.txt @@ -1,3 +1,8 @@ +Patch +-Update Added Visage to the AppDiff ignore list +-Fix Capped ping attempts to one in CMDB fallback so it doesn't hang on offline computers +-Fix IP Address queries now resolve to the hostname correctly, but does not act as a workaround for duplicate A records + Patch 2025-3-20 -Update GPUpdate is now more robust by clearing more files and registry keys