From e30dfa2aaa97c920075fa45887e59eda057808ee Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Thu, 29 Aug 2024 09:44:47 -0700 Subject: [PATCH] CMDB flag, Apps computer column, and coast hostname fix --- Get-PC.psd1 | 2 +- Private/Apps.ps1 | 2 ++ Private/Get-CMDBFallback.ps1 | 6 +++--- Private/Get-Hostname.ps1 | 9 +++++++-- Private/SCCMQuery.ps1 | 4 ++-- Public/Get-PC.ps1 | 38 +++++++++++++++++++++++++++++------- patchnotes.txt | 6 ++++++ 7 files changed, 52 insertions(+), 15 deletions(-) diff --git a/Get-PC.psd1 b/Get-PC.psd1 index db0d6c9..33941f4 100644 --- a/Get-PC.psd1 +++ b/Get-PC.psd1 @@ -12,7 +12,7 @@ RootModule = 'Get-PC.psm1' # Version number of this module. -ModuleVersion = '0.4.3' +ModuleVersion = '0.4.4' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/Private/Apps.ps1 b/Private/Apps.ps1 index fa19a5e..47cb2fb 100644 --- a/Private/Apps.ps1 +++ b/Private/Apps.ps1 @@ -5,6 +5,7 @@ #Checks if local computer if ($ComputerName -eq $env:COMPUTERNAME) { $localapps = Get-Package -ProviderName Programs -IncludeWindowsInstaller | + Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru | Select-Object @{N='DisplayName';E={$_.Name}},* | Sort-Object -Property DisplayName } else { @@ -12,6 +13,7 @@ if (Test-Connection -ComputerName $ComputerName -Count 1) { $localapps = Invoke-Command -ComputerName $ComputerName -SessionOption $(New-PSSessionOption -MaxConnectionRetryCount 1 -NoMachineProfile) -ScriptBlock { Get-Package -ProviderName Programs -IncludeWindowsInstaller | + Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru | Select-Object @{N='DisplayName';E={$_.Name}},* | Sort-Object -Property DisplayName } diff --git a/Private/Get-CMDBFallback.ps1 b/Private/Get-CMDBFallback.ps1 index 40bd720..7c82aff 100644 --- a/Private/Get-CMDBFallback.ps1 +++ b/Private/Get-CMDBFallback.ps1 @@ -134,10 +134,10 @@ function Get-CMDBFallback { Model = $cmdbData.Model + ' (' + $cmdbData.ivnt_assetsubtype + ')' 'OS' = $cmdbData.OperatingSystem + " " + $cmdbData.OSMajorVersion 'OS Build' = $cmdbData.OSMajorVersion - 'BIOS Ver' = $cmdbData.BIOSVersion + " ($($cmdbData.BiosDate))" + 'BIOS Ver' = "$($cmdbData.BIOSVersion) ($($cmdbData.BiosDate))" Encryption = $cmdbData.ivnt_EncryptionState - 'Free Space' = $diskData.FreeSpace + ' GB / ' + $diskData.capacity + ' GB' - 'RAM' = $MemoryTotal+ " GB " + 'Free Space' = "$($diskData.FreeSpace) GB / $($diskData.capacity) GB" + 'RAM' = "$MemoryTotal GB " 'SSO Client' = "Not Available" # 'Kiosk Role' = "Not Available" 'Asset Tag' = $cmdbData.AssetTag diff --git a/Private/Get-Hostname.ps1 b/Private/Get-Hostname.ps1 index 6c88132..264bb78 100644 --- a/Private/Get-Hostname.ps1 +++ b/Private/Get-Hostname.ps1 @@ -13,7 +13,7 @@ function Get-Hostname ([string]$name) { 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")) { - return $Matches[1],'' + return $Matches[0],'' } else { $errMsg += "$name IP Address couldn't be resolved to hostname" } @@ -33,6 +33,11 @@ function Get-Hostname ([string]$name) { if ($res) { return $res,'' } else { $errMsg += "$name MAC Address not found in SCCM"} } - + + $cmdbMatches = Find-ISMBO -bo cis -SearchQuery $name + if ($cmdbMatches -and $cmdbMatches.Count -lt 2) { + return $cmdbMatches.Name,'' + } + return $name, $errMsg } \ No newline at end of file diff --git a/Private/SCCMQuery.ps1 b/Private/SCCMQuery.ps1 index 7d8b55c..b919ff9 100644 --- a/Private/SCCMQuery.ps1 +++ b/Private/SCCMQuery.ps1 @@ -442,10 +442,10 @@ function Get-SCCM_Apps($ComputerName) { SMS_G_System_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_G_System_SYSTEM.Name = '$ComputerName'" $64apps = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMX64Query | - Select-Object -Property DisplayName,Version,Publisher,InstallDate | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 64 -PassThru | Sort-Object -Property DisplayName + Select-Object -Property DisplayName,Version,Publisher,InstallDate | Add-Member -NotePropertyName Computer -NotePropertyValue $ComputerName -PassThru | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 64 -PassThru | Sort-Object -Property DisplayName $86apps = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMX86Query | - Select-Object -Property DisplayName,Version,Publisher,InstallDate | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 32 -PassThru | Sort-Object -Property DisplayName + Select-Object -Property DisplayName,Version,Publisher,InstallDate | Add-Member -NotePropertyName Computer -NotePropertyValue $ComputerName -PassThru | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 32 -PassThru | Sort-Object -Property DisplayName return $86apps, $64apps } diff --git a/Public/Get-PC.ps1 b/Public/Get-PC.ps1 index a2d1290..ac3e73c 100644 --- a/Public/Get-PC.ps1 +++ b/Public/Get-PC.ps1 @@ -21,6 +21,8 @@ elseif ($devStage -eq "Dev") { $deployedVersion = (Test-ModuleManifest $getPCDevBuildPath).Version } +$getPCWrappedPath = '\\int.samhealth.net\files\TEAM\SHSISDesktopSolutions\Powershell\Get-PC_Update_2023\Get-PC-Wrapped\backlog.txt' + #lets user know when get-pc has been imported and what version they are running Write-Host "`nGet-PC Module Version $Version [$devStage] Loaded." -ForegroundColor Green if ($Version -ne $deployedVersion) { @@ -41,6 +43,7 @@ Function Get-PC { -AppDiff | shows the installed applications that are not in the standard image -Bypass | used in conjuction with remote viewer will bypass user prompt -ClearCCMCache | clears CCM cache, may fix software center + -CMDB | only queries CMDB for info -Devices | shows connected monitors and usb devices -EventLog | pulls up errors in the event log for the last x days -Excel | exports collected data to csv and opens it with excel @@ -89,6 +92,7 @@ Function Get-PC { [Switch]$AppDiff, [Switch]$Bypass, [Switch]$ClearCCMCache, + [Switch]$CMDB, [switch]$Devices, [Switch]$EventLog, [switch]$Excel, @@ -124,6 +128,17 @@ Function Get-PC { [Switch]$WinProfileRebuild ) + <# + #Data collection for Get-PC Wrapped TM + $invokeData = @{ + Hostname = $env:COMPUTERNAME + Username = $env:USERNAME + Datetime = Get-Date -Format 'yyyy-MM-ddThh:mm:ss.fffffff' + Parameters = $MyInvocation.BoundParameters + } + Add-Content -Path $getPCWrappedPath -Value $(ConvertTo-Json -Compress $invokeData) + #> + ## Define which Spark Record Properties are Returned $Spark_Property_Return = @( "Name", @@ -136,10 +151,12 @@ Function Get-PC { "Status" ) + <# if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Write-Warning "Get-PC requires powershell to be run as administrator. Please re-launch powershell as administrator." break } + #> # Stuff only run once if ($Update) { @@ -198,14 +215,17 @@ Function Get-PC { Write-Host "Starting CMDB Wildcard Search..." # $searchResults = Search-CMDB -hostname $ComputerName.Replace('*','') | Sort-Object -Property Hostname + $output = @() + foreach ($comp in $ComputerName) { + $searchResults = Find-ISMBO -BusinessObject "cis" -SearchQuery $comp | Sort-Object -Property Name - $searchResults = Find-ISMBO -BusinessObject "cis" -SearchQuery $ComputerName.Replace('*','') | Sort-Object -Property Name - - Write-Output $searchResults | Select-Object $Spark_Property_Return - if($TableView){ - $searchResults | Select-Object $Spark_Property_Return | Out-GridView -Title 'Get-PC Wildcard Search' + $output += Write-Output $searchResults | Select-Object $Spark_Property_Return } - return + #$searchResults = Find-ISMBO -BusinessObject "cis" -SearchQuery $ComputerName.Replace('*','') | Sort-Object -Property Name + if($TableView){ + $output | Out-GridView -Title 'Get-PC Wildcard Search' + } + return $output } @@ -222,7 +242,6 @@ Function Get-PC { continue } - $oldcomp = $comp $comp,$msg = Get-Hostname $comp if ($msg -and -not $SHSPrinter) { Write-Host "`n$msg" -ForegroundColor Red @@ -257,6 +276,11 @@ Function Get-PC { continue } + if ($CMDB) { + $outputArray += Get-CMDBFallback $comp + continue + } + #DREW SUCKS #Pulls basic SNMP Data from printer $comp diff --git a/patchnotes.txt b/patchnotes.txt index be3be38..2cfb4e6 100644 --- a/patchnotes.txt +++ b/patchnotes.txt @@ -1,3 +1,9 @@ +Patch: 2024-08-29 +-Add CMDB flag to just query CMDB for fields +-Fix bug in CMDB Fallback not reporting RAM correctly +-Apps has the Computer column again +-Fix Coast hostnames are checked against CMDB before rejecting as bad SN + Patch: 2024-08-14 -Add CMDB fallback added when hostname not in SCCM -Fix Get-Hostname to query cmdb for asset tags if not in SCCM