From 00d4adfe7b6e696a497c9c8942ac417ba34dea8d Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Tue, 13 Aug 2024 16:40:16 -0700 Subject: [PATCH] Get-pc falls back to cmdb when pc is offline and not in SCCM --- Private/BatchInvokes.ps1 | 15 ++++++++++++--- Public/Get-PC.ps1 | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Private/BatchInvokes.ps1 b/Private/BatchInvokes.ps1 index cd0d3fa..a997311 100644 --- a/Private/BatchInvokes.ps1 +++ b/Private/BatchInvokes.ps1 @@ -392,7 +392,6 @@ function Get-PCBatchInvoke { } BatchInvokesProgressBar -stage 3 $output += $invokeJob | Receive-Job -Wait -AutoRemoveJob | Select-Object * -ExcludeProperty RunspaceId, PSComputerName, PSShowComputerName, PSSourceJobInstanceId - $output += $offlineJobs | Receive-Job -Wait -AutoRemoveJob | Select-Object * -ExcludeProperty RunspaceId, PSComputerName, PSShowComputerName, PSSourceJobInstanceId $itemIndex = 0 $contactedhosts = $output.Hostname BatchInvokesProgressBar -stage 4 @@ -403,7 +402,16 @@ function Get-PCBatchInvoke { $missedJobs += Start-Job -ScriptBlock ${function:Get-SCCMQueryBlock} -ArgumentList $computer } } + $output += $offlineJobs | Receive-Job -Wait -AutoRemoveJob | Select-Object * -ExcludeProperty RunspaceId, PSComputerName, PSShowComputerName, PSSourceJobInstanceId $output += $missedJobs | Receive-Job -Wait -AutoRemoveJob | Select-Object * -ExcludeProperty RunspaceId, PSComputerName, PSShowComputerName, PSSourceJobInstanceId + BatchInvokesProgressBar -stage 5 + #CMDB cycle of missed hosts + $missedhosts = $Computers | Where-Object -FilterScript {$_ -notin $output.Hostname} + if($missedhosts.count -gt 0){ + foreach($computer in $missedhosts){ + $output += Get-CMDBFallback $computer + } + } return $output @@ -445,8 +453,9 @@ function BatchInvokesProgressBar { switch ($stage) { 1 { Write-Progress -Activity "Connecting to computers" -Status "$item ($currentItemIndex/$TotalItems)" -PercentComplete (($currentItemIndex/$TotalItems) * 100)} 2 { Write-Progress -Activity "Spinning up jobs" -PercentComplete ((20/100) * 100)} - 3 { Write-Progress -Activity "Awaiting Jobs" -PercentComplete ((60/100)*100)} - 4 { Write-Progress -Activity "Querying SCCM for missed computers" -PercentComplete ((75/100) * 100)} + 3 { Write-Progress -Activity "Awaiting Online Jobs" -PercentComplete ((60/100)*100)} + 4 { Write-Progress -Activity "Querying SCCM for offline computers" -PercentComplete ((75/100) * 100)} + 5 { Write-Progress -Activity "Querying CMDB for computers not in SCCM" -PercentComplete ((75/100) * 100)} Default {} } diff --git a/Public/Get-PC.ps1 b/Public/Get-PC.ps1 index 7501a8f..a2d1290 100644 --- a/Public/Get-PC.ps1 +++ b/Public/Get-PC.ps1 @@ -4,7 +4,7 @@ #region Module Import Block -#$ErrorActionPreference = 'SilentlyContinue' +$ErrorActionPreference = 'SilentlyContinue' #DevStage can take either Dev or Prod as values $devStage = 'Dev' #Locations for dev build and prod build