diff --git a/Get-PC.psd1 b/Get-PC.psd1 index 2c17342..9355acc 100644 --- a/Get-PC.psd1 +++ b/Get-PC.psd1 @@ -12,7 +12,7 @@ RootModule = 'Get-PC.psm1' # Version number of this module. -ModuleVersion = '0.3.15' +ModuleVersion = '0.3.16' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/Private/BatchInvokes.ps1 b/Private/BatchInvokes.ps1 index 8656731..5f90c83 100644 --- a/Private/BatchInvokes.ps1 +++ b/Private/BatchInvokes.ps1 @@ -22,7 +22,7 @@ function Get-PCBatchInvoke { Write-Progress -Activity "Retrieving data from online computers" -Status $Env:COMPUTERNAME -PercentComplete 40 try {$kioskRegEntry = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\SHSCustom} catch {$kioskRegEntry = $null} try {$win32_tpm = Get-CimInstance -Namespace root\cimv2\security\microsofttpm -Class win32_tpm} catch{$win32_tpm = $null} # | TPM - + $gpoPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\FVE\MDOPBitLockerManagement" $gpoValue = Get-ItemPropertyValue -Path $gpoPath -Name "KeyRecoveryServiceEndPoint" @@ -199,11 +199,8 @@ function Get-PCBatchInvoke { Default {$ImprivataType = "Not Installed"} } } - $kioskRole = try {$kioskRegEntry | Select-Object -ExpandProperty KioskRole} catch{$kioskRole = $null} - if(!$kioskRole){ - $kioskRole = "None" - } - + $kioskRole = try {$kioskRegEntry | Select-Object -ExpandProperty KioskRole} catch{ $null } + if (!$kioskRole) { $kioskRole = "None"} #TPM if($win32_tpm){ @@ -352,32 +349,24 @@ function Get-PCBatchInvoke { } BatchInvokesProgressBar -stage 2 $jobs = Invoke-Command -ScriptBlock $sblock -ComputerName $OnlineComputers -SessionOption (New-PSSessionOption -NoMachineProfile -OpenTimeout 45000) -AsJob + BatchInvokesProgressBar -stage 3 if($OfflineComputers.count -gt 0){ foreach($computer in $OfflineComputers){ - $jobs += Start-Job -ScriptBlock { - $offlineCompData = Get-SCCMQuery -comp $computer -NumberofComputers $OfflineComputers.count -PCID $itemIndex - if($null -eq $offlineCompData.'Last Reboot'){ - $offlineCompData = Get-CMDBFallback -comp $computer - } - Write-Output $offlineCompData - } + $jobs += Start-Job -ScriptBlock ${function:SCCMQueryBlock} -ArgumentList $computer } } - BatchInvokesProgressBar -stage 3 - $output += $jobs | Receive-Job -Wait | Select-Object * -ExcludeProperty RunspaceId, PSComputerName, PSShowComputerName + BatchInvokesProgressBar -stage 4 + $output += $jobs | Receive-Job -Wait -AutoRemoveJob | Select-Object * -ExcludeProperty RunspaceId, PSComputerName, PSShowComputerName $itemIndex = 0 $contactedhosts = $output.Hostname - BatchInvokesProgressBar -stage 4 + BatchInvokesProgressBar -stage 5 $missedhosts = $OnlineComputers | Where-Object -FilterScript {$_ -notin $contactedhosts} if($missedhosts.count -gt 0){ - foreach($computer in $OfflineComputers){ - $offlineCompData = Get-SCCMQuery -comp $computer -NumberofComputers $OfflineComputers.count -PCID $itemIndex - if($null -eq $offlineCompData.'Last Reboot'){ - $offlineCompData = Get-CMDBFallback -comp $computer - } - $output += $offlineCompData + foreach($computer in $missedhosts){ + $jobs += Start-Job -ScriptBlock ${function:SCCMQueryBlock} -ArgumentList $computer } } + $output += $jobs | Receive-Job -Wait -AutoRemoveJob | Select-Object * -ExcludeProperty RunspaceId, PSComputerName, PSShowComputerName return $output @@ -418,8 +407,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 ((50/100) * 100)} - 3 { Write-Progress -Activity "Awaiting Jobs" -PercentComplete ((55/100)*100)} + 2 { Write-Progress -Activity "Spinning up jobs" -PercentComplete ((20/100) * 100)} + 4 { Write-Progress -Activity "Querying SCCM for offline computers" -PercentComplete ((30/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)} Default {} } diff --git a/Private/BatchJobs.ps1 b/Private/BatchJobs.ps1 index 7ba2e46..02ff653 100644 --- a/Private/BatchJobs.ps1 +++ b/Private/BatchJobs.ps1 @@ -8,8 +8,6 @@ function Get-PCBatchJob{ $Computers, [switch]$printers ) - $modulePath = (get-item $PSScriptRoot).Parent.FullName - $modulePath = "$modulePath\Get-PC.psd1" $TotalItems = $Computers.count $ActiveJobs = @() $itemIndex = 0 @@ -17,15 +15,11 @@ function Get-PCBatchJob{ if($printers){ JobsProgressBar $c $itemIndex $TotalItems 1 - $ActiveJobs += Start-Job -Name $c -ArgumentList $c,$modulePath -ScriptBlock{ - Import-Module $args[1] -WarningAction Ignore - get-pc $args[0] -SHSPrinter} + $ActiveJobs += Start-Job -Name $c -ScriptBlock ${function:Get-SHSPrinter} -ArgumentList $c } else{ JobsProgressBar $c $itemIndex $TotalItems 1 - $ActiveJobs += Start-Job -Name $c -ArgumentList $c,$modulePath -ScriptBlock{ - Import-Module $args[1] -WarningAction Ignore - get-pc $args[0]} + $ActiveJobs += Start-Job -Name $c -ScriptBlock ${function:get-pc} -ArgumentList $c } $itemIndex++ } @@ -33,19 +27,12 @@ function Get-PCBatchJob{ $completedJobs = @() $itemIndex = 0 JobsProgressBar 'Waiting on jobs to be' $itemIndex $TotalItems 2 - While(!$jobsDone){ - $jobsDone = $true - foreach ($job in $ActiveJobs){ - if($job.State -eq 'Running'){ - $jobsDone = $false - } - if($job.State -eq 'Completed' -and !$completedJobs.Contains($job)){ - $itemIndex++ - JobsProgressBar $job.Name $itemIndex $TotalItems 2 - $completedJobs += $job - } - } - Start-Sleep -Milliseconds 1 + While($ActiveJobs.Length){ + $job = Wait-Job -Any $ActiveJobs + $itemIndex++ + JobsProgressBar $job.Name $itemIndex $TotalItems 2 + $completedJobs += $job + $ActiveJobs = $ActiveJobs | Where-Object { $_.Name -ne $job.Name } } $itemIndex = 0 foreach($job in $completedJobs) { @@ -54,9 +41,7 @@ function Get-PCBatchJob{ $output = Receive-Job $job | Select-Object * -ExcludeProperty RunspaceId, PSComputerName, PSShowComputerName Remove-job $job Write-Output $output - } - } function JobsProgressBar { diff --git a/Private/SCCMQueryBlock.ps1 b/Private/SCCMQueryBlock.ps1 new file mode 100644 index 0000000..b39dbc1 --- /dev/null +++ b/Private/SCCMQueryBlock.ps1 @@ -0,0 +1,284 @@ +#CONST +$SITENAME="100" +$SCCMSERVER="shscm01.int.samhealth.net" +$SCCMNAMESPACE="root\sms\site_100" + +Function Get-SCCMQueryBlock { + param ( + [string]$comp, + [int]$NumberofComputers, + [int]$PCID + ) + + if(!(Test-Connection -ComputerName $comp -Count 1)){ + + $compStatus = "Offline" + } + else{ + $compStatus = "Online" + } + + if(get-module -ListAvailable -Name 'ActiveDirectory'){ + try { $adTest = ((Get-ADComputer $comp).DistinguishedName -match "Disabled Computers") } catch { $adTest = $true } + if($adTest){ + $compStatus += " (disabled or off the domain)" + } + } + + $i = 0 + $i++ | ProgressBar $i $comp "SCCM Last Hardware Scan" $NumberofComputers $PCID + #Last Hardware Scan + $FindLastHardwareScanQuery = "select SMS_G_System_WORKSTATION_STATUS.LastHardwareScan from SMS_R_System inner join SMS_G_System_WORKSTATION_STATUS on SMS_G_System_WORKSTATION_STATUS.ResourceID = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'" + + $FindLastHardwareScanSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindLastHardwareScanQuery | Select-Object -ExpandProperty LastHardwareScan + + if($null -eq $FindLastHardwareScanSCCM){ + return $null + } + + $Year = $FindLastHardwareScanSCCM.substring(0,4) + $Month = $FindLastHardwareScanSCCM.substring(4,2) + $Day = $FindLastHardwareScanSCCM.substring(6,2) + + $Hour = $FindLastHardwareScanSCCM.substring(8,2) + $Minute = $FindLastHardwareScanSCCM.substring(10,2) + $Second = $FindLastHardwareScanSCCM.substring(12,2) + + $FindLastHardwareScanSCCM = "$Month/$Day/$Year $Hour" + ":" + "$Minute" + ":" + "$Second" + #End Last Hardware Scan + + if(!$FindLastHardwareScanSCCM){ + $props = [Ordered]@{ + Hostname = "$comp" + Status = "$compStatus" + 'Current User' = $null + 'Last User(s)' = $null + 'IP | MAC' = $null + Model = $null + 'OS' = $null + 'OS Build' = $null + 'BIOS Ver' = $null + Encryption = $null + 'Free Space' = $null + RAM = $null + 'SSO Client' = $null + 'Kiosk Role' = $null + 'Asset Tag' = $null + 'Service Tag' = $null + 'Last Reboot' = $null + Printers = $null + } + + $obj = New-Object -TypeName PSObject -Property $props + + return $obj + } + $i++ | ProgressBar $i $comp "Last User SCCM" $NumberofComputers $PCID + $SCCMLastUserLogOnQuery = "select SMS_R_System.LastLogonUserName from SMS_R_System where SMS_R_System.Name = '$ComputerName'" + $LastUserSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $SCCMLastUserLogOnQuery | + Select-Object -ExpandProperty LastLogonUserName + + $i++ | ProgressBar $i $comp "SCCM IP Query" $NumberofComputers $PCID + $FindIPQuery = "select SMS_R_System.IPAddresses from SMS_R_System where SMS_R_System.Name = '$ComputerName'" + $FindIPSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindIPQuery | + Select-Object -ExpandProperty IPAddresses + if($FindIPSCCM.Count -gt 1){ + $FindIPSCCM = $FindIPSCCM[0] + } + + $i++ | ProgressBar $i $comp "Find Model SCCM" $NumberofComputers $PCID + $FindModelQuery = "select SMS_G_System_COMPUTER_SYSTEM.Model from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on + SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'" + $CompModelSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindModelQuery | + Select-Object -ExpandProperty Model + + $i++ | ProgressBar $i $comp "SCCM Bios Version" $NumberofComputers $PCID + $FindBiosVerQuery = "select SMS_G_System_PC_BIOS.SMBIOSBIOSVersion from SMS_R_System inner join SMS_G_System_PC_BIOS on + SMS_G_System_PC_BIOS.ResourceId = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'" + $FindBiosVerSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindBiosVerQuery | + Select-Object -ExpandProperty SMBIOSBIOSVersion + + $i++ | ProgressBar $i $comp "SCCM HDD/SSD Space" $NumberofComputers $PCID + $FindFreeSpaceQuery = "select SMS_G_System_LOGICAL_DISK.Size from SMS_R_System inner join SMS_G_System_LOGICAL_DISK on + SMS_G_System_LOGICAL_DISK.ResourceID = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'" + $CompFreeSpaceSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindFreeSpaceQuery | + Select-Object -ExpandProperty Size + $CompFreeSpaceSCCMGB = [math]::Round(($CompFreeSpaceSCCM / 1000), 2) + + $i++ | ProgressBar $i $comp "SCCM RAM" $NumberofComputers $PCID + $FindMemoryQuery = "select SMS_G_System_X86_PC_MEMORY.TotalPhysicalMemory from SMS_R_System inner join SMS_G_System_X86_PC_MEMORY on + SMS_G_System_X86_PC_MEMORY.ResourceID = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'" + $FindMemorySCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindMemoryQuery | + Select-Object -ExpandProperty TotalPhysicalMemory + $FindMemorySCCMGB = [math]::Round($FindMemorySCCM / 1MB) + + $i++ | ProgressBar $i $comp "SCCM Asset Tag" $NumberofComputers $PCID + $FindAssetTagQuery = "select SMS_G_System_SYSTEM_ENCLOSURE.SMBIOSAssetTag from SMS_R_System inner join SMS_G_System_SYSTEM_ENCLOSURE on + SMS_G_System_SYSTEM_ENCLOSURE.ResourceId = SMS_R_System.ResourceId inner join SMS_G_System_SYSTEM on SMS_G_System_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_SYSTEM.Name = '$ComputerName'" + $FindAssetTagSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindAssetTagQuery | + Select-Object -ExpandProperty SMBIOSAssetTag + + $i++ | ProgressBar $i $comp "SCCM Service Tag" $NumberofComputers $PCID + $FindServiceTagQuery = "select SMS_G_System_SYSTEM_ENCLOSURE.SerialNumber from SMS_R_System inner join SMS_G_System_SYSTEM_ENCLOSURE on + SMS_G_System_SYSTEM_ENCLOSURE.ResourceId = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'" + $FindServiceTagSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindServiceTagQuery | + Select-Object -ExpandProperty SerialNumber + + $i++ | ProgressBar $i $comp "SCCM OS Name" $NumberofComputers $PCID + $FindOSNameQuery = "select SMS_G_System_OPERATING_SYSTEM.Caption, SMS_G_System_OPERATING_SYSTEM.OSArchitecture, SMS_G_System_OPERATING_SYSTEM.BuildNumber from + SMS_R_System inner join SMS_G_System_OPERATING_SYSTEM on SMS_G_System_OPERATING_SYSTEM.ResourceID = + SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'" + $FindOSNameSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindOSNameQuery | + Select-Object -ExpandProperty Caption + + $i++ | ProgressBar $i $comp "SCCM OS Architecture" $NumberofComputers $PCID + $FindOSNameQuery = "select SMS_G_System_OPERATING_SYSTEM.Caption, SMS_G_System_OPERATING_SYSTEM.OSArchitecture, SMS_G_System_OPERATING_SYSTEM.BuildNumber from + SMS_R_System inner join SMS_G_System_OPERATING_SYSTEM on SMS_G_System_OPERATING_SYSTEM.ResourceID = + SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'" + $FindOSArchSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindOSNameQuery | + Select-Object -ExpandProperty OSArchitecture + + $i++ | ProgressBar $i $comp "SCCM OS Build" $NumberofComputers $PCID + $FindOSNameQuery = "select SMS_G_System_OPERATING_SYSTEM.Caption, SMS_G_System_OPERATING_SYSTEM.OSArchitecture, SMS_G_System_OPERATING_SYSTEM.BuildNumber from + SMS_R_System inner join SMS_G_System_OPERATING_SYSTEM on SMS_G_System_OPERATING_SYSTEM.ResourceID = + SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'" + $FindOSBuild = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindOSNameQuery | + Select-Object -ExpandProperty BuildNumber + + $i++ | ProgressBar $i $comp "SCCM Encryption" $NumberofComputers $PCID + $FindEncryptionQuery = "select SMS_G_System_ENCRYPTABLE_VOLUME.ProtectionStatus from SMS_R_System inner join SMS_G_System_ENCRYPTABLE_VOLUME on + SMS_G_System_ENCRYPTABLE_VOLUME.ResourceId = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'" + $FindEncryptionSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindEncryptionQuery | + Select-Object -ExpandProperty ProtectionStatus + Switch($FindEncryptionSCCM){ + 0{$FindEncryptionSCCM = "BitLocker (Disabled)"} + 1{$FindEncryptionSCCM = "BitLocker (Enabled [Unlocked])"} + 2{$FindEncryptionSCCM = "BitLocker (Enabled [Locked])"} + Default{$FindEncryptionSCCM = "Encryption Not Found"} + } + + $i++ | ProgressBar $i $comp "SCCM Last Boot Up Time" $NumberofComputers $PCID + $FindLastBootUpTimeSCCM = Get-SCCMLastBootUpTime $comp + $FindLastBootUpTimeQuery = "select SMS_G_System_OPERATING_SYSTEM.LastBootUpTime from SMS_R_System inner join SMS_G_System_OPERATING_SYSTEM on + SMS_G_System_OPERATING_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'" + + $FindLastBootUpTimeSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindLastBootUpTimeQuery | + Select-Object -ExpandProperty LastBootUpTime + if($null -ne $FindLastBootUpTimeSCCM){ + $Year = $FindLastBootUpTimeSCCM.substring(0,4) + $Month = $FindLastBootUpTimeSCCM.substring(4,2) + $Day = $FindLastBootUpTimeSCCM.substring(6,2) + $Hour = $FindLastBootUpTimeSCCM.substring(8,2) + $Minute = $FindLastBootUpTimeSCCM.substring(10,2) + $Second = $FindLastBootUpTimeSCCM.substring(12,2) + $FindLastBootUpTimeSCCM = "$Month/$Day/$Year $Hour" + ":" + "$Minute" + ":" + "$Second" + } + + $i++ | ProgressBar $i $comp "SCCM Printers" $NumberofComputers $PCID + $FindPCPrinterQuery = "select SMS_G_System_PRINTER_DEVICE.Name, SMS_G_System_PRINTER_DEVICE.PortName from SMS_R_System inner join SMS_G_System_PRINTER_DEVICE + on SMS_G_System_PRINTER_DEVICE.ResourceID = SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'" + $FindPCPrinterSCCM = (Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindPCPrinterQuery | + Where-Object -Property PortName -ne nul: | + Where-Object -Property PortName -ne PORTPROMPT: | + Where-Object -Property PortName -ne SHRFAX: | Select-Object -ExpandProperty Name) -join ' || ' + + $i++ | ProgressBar $i $comp "SCCM MACAddress" $NumberofComputers $PCID + $FindMACAddressSCCM = Get-SCCMFindMACAddress $comp + + $i++ | ProgressBar $i $comp "SCCM Chassis Type" $NumberofComputers $PCID + $FindProcessorQuery = "select SMS_G_System_PROCESSOR.Name from SMS_R_System inner join SMS_G_System_PROCESSOR on SMS_G_System_PROCESSOR.ResourceId = SMS_R_System.ResourceId inner join SMS_G_System_SYSTEM on + SMS_G_System_SYSTEM.ResourceId = SMS_R_System.ResourceId where SMS_G_System_SYSTEM.Name = '$ComputerName'" + $FindProcessorSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindProcessorQuery | Select-Object -ExpandProperty Name + $Model = Get-SCCMFindModelQuery $ComputerName + $FindChassisTypeSCCM = Switch -Wildcard($Model){ + "Optiplex*" { + Switch -Wildcard($FindProcessorSCCM){ + "Intel(R) Core(TM) i5-9500 CPU*" {"SFF"} #5070 + + "Intel(R) Core(TM) i5-6500 CPU*" {"SFF"} #7040 + + "Intel(R) Core(TM) i5-6500T*" {"Micro"} #7040 + + "Intel(R) Core(TM) i7-6700 CPU*" {"SFF"} #7040 + + "Intel(R) Core(TM) i7-6700T*" {"Micro"} #7040 + + "Intel(R) Core(TM) i5-9500T*" {"Micro"} #5070 + + "Intel(R) Core(TM) i5-8500 CPU*" {"SFF"} #5060 + + "Intel(R) Core(TM) i5-8500T*" {"Micro"} #5060 + + "Intel(R) Core(TM) i5-7500*" {"SFF"} #5050 + + "Intel(R) Core(TM) i5-4670 CPU*" {"SFF"} #9020 + + "Intel(R) Core(TM) i5-4590 CPU*" {"SFF"} #9020 + + "Intel(R) Core(TM) i5-4590T CPU*" {"Micro"} #9020M + + "Intel(R) Core(TM) i5-4690 CPU*" {"SFF"} #9020 + + "Intel(R) Core(TM) i5-3550 CPU*" {"SFF"} #9010 + + "Intel(R) Core(TM) i5-2400 CPU*" {"SFF"} #990 + + Default {"Optiplex - Chassis Type - Unknown"} + } + + } + + "Latitude*" {"Laptop"} + "Precision*"{"Laptop"} + "M24*" {"Anesthesia Cart"} + "Medix*"{"Anesthesia Cart"} + + Default {"Unknown Model/Chassis"} + } + + if($FindAssetTagSCCM -is [array]){ + Write-Warning "Dupe record in SCCM - $comp" + $FindAssetTagSCCM = $FindAssetTagSCCM[0] + <#Get-CMDBFallback $comp#> + } + + <#$cmdbData = Get-CMDBData $comp $FindAssetTagSCCM + $MDBLcmdblocation = Get-Cocation $cmdbData + #> + + if($FindLastHardwareScanSCCM){ + Write-Host "`n`nPulling cached SCCM data for $comp." -ForegroundColor Yellow + Write-Host "Last Hardware Scan Time: $FindLastHardwareScanSCCM" -ForegroundColor Yellow + } + + + $props = [Ordered]@{ + Hostname = "$comp" + Status = "$compStatus" + 'Current User' = "Not Available" + 'Last User(s)' = "$LastUserSCCM" + 'IP | MAC' = "$FindIPSCCM | $FindMACAddressSCCM" + Model = "$CompModelSCCM ($FindChassisTypeSCCM)" + 'OS' = "$FindOSNameSCCM" + " ($FindOSArchSCCM)" + 'OS Build' = "Build #$FindOSBuild" + 'BIOS Ver' = "$FindBiosVerSCCM" + Encryption = "$FindEncryptionSCCM" + 'Free Space' = "$CompFreeSpaceSCCMGB" + " GB" + RAM = "$FindMemorySCCMGB" + " GB " + 'SSO Client' = "Not Available" + 'Kiosk Role' = "Not Available" + 'Asset Tag' = "$FindAssetTagSCCM" + 'Service Tag' = "$FindServiceTagSCCM" + 'Last Reboot' = "$FindLastBootUpTimeSCCM" + Printers = "$FindPCPrinterSCCM" + } + + $obj = New-Object -TypeName PSObject -Property $props + <#if($cmdbData.values.ConfigurationItem._SHSDELAsset -eq 'True'){ + $delInfo = Get-CMDBDELInfo $cmdbData + $obj | Add-Member -MemberType NoteProperty -Name 'DEL Owner' -Value $delInfo.Owner + $obj | Add-Member -MemberType NoteProperty -Name 'DEL Vendor PC' -Value $delInfo.Vendor + $obj | Add-Member -MemberType NoteProperty -Name 'DEL Description' -Value $delInfo.Description + } #> + return $obj +} diff --git a/Private/SHSPrinter.ps1 b/Private/SHSPrinter.ps1 index 4666da0..f55364d 100644 --- a/Private/SHSPrinter.ps1 +++ b/Private/SHSPrinter.ps1 @@ -21,38 +21,46 @@ function Get-SHSPrinter { foreach ($printer in $printers) { #Gets the printer ip and full domain name - $result = Get-PrinterIP $printer - + $hit = $false + $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) { + $hit = $false + foreach ($domain in $domains) { + $search = "$printer$domain" + $result = Resolve-DnsName $search -ErrorAction SilentlyContinue + if ($null -ne $result) { + $hit = $true + $name = $result.Name + $ip = $result.IPAddress + + + } + + } + + if ($null -eq $result) { + if ($hit -eq $false) { + $ip = $null + $name = $null + } + } + } + else { + $name = $result.Name + $ip = $result.IPAddress + + } + + $result = [ordered]@{Hostname = $printer + IP = $ip + Path = $name + } + #CMDB Data - $cmdbRecord = Get-LANDeskCMDBItem -Name $printer - if ($cmdbRecord.values._SHSLocation3.Length -gt $cmdbRecord.values._SHSCalcLocationString.Length) { - $locationData = $cmdbRecord.values._SHSLocation3 - } - else { - $locationData = $cmdbRecord.values._SHSCalcLocationString - } - if ($cmdbRecord) { - $CMDB_POA = $cmdbRecord.values._SHSPOANumber - $CMDB_AssetTag = $cmdbRecord.values._SHSAssetTag - $CMDB_Location = $locationData - $CMDB_MAC = $cmdbRecord.values._SHSMACAddress - $CMDB_model = $cmdbRecord.values._Model - $CMDB_serial = $cmdbRecord.values._SerialNumber - $CMDB_IP = $cmdbRecord.values._IPAddress - } - else { - $CMDB_POA = "*CMDB Mismatch - check CMDB*" - $CMDB_AssetTag = "*CMDB Mismatch - check CMDB*" - $CMDB_Location = "*CMDB Mismatch - check CMDB*" - $CMDB_MAC = "*CMDB Mismatch - check CMDB*" - $CMDB_model = "*CMDB Mismatch - check CMDB*" - $CMDB_serial = "*CMDB Mismatch - check CMDB*" - $CMDB_IP = "*CMDB Mismatch - check CMDB*" - } - if ($null -ne $result.IP) { - $printerip = $result.IP $domainName = $result.Path @@ -60,8 +68,6 @@ function Get-SHSPrinter { #checks to see if the printer is online $online = Test-Connection $printerip -ErrorAction SilentlyContinue - - if ($online) { #opens snmp connection to the printer $snmp.open($printerip, 'public', 2, 3000) @@ -274,9 +280,6 @@ function Get-SHSPrinter { #Addresses = $addr PageCount = $pagecount Supplies = $supplies - 'CMDB POA' = $CMDB_POA - 'CMDB AssetTag' = $CMDB_AssetTag - 'CMDB Location' = $CMDB_Location } $obj = New-Object -TypeName PSObject -Property $props $snmp.close() @@ -285,27 +288,19 @@ function Get-SHSPrinter { } } - if ($CMDB_IP) { - $offlineIP = 'CMDB IP - ' + $CMDB_IP - } - else { - $offlineIP = 'No DNS Entry' - } + $props = [Ordered]@{ Machine = $printer Status = 'No DNS Entry' - IP = $offlineIP + IP = 'No DNS Entry' DomainName = 'No DNS Entry' - MAC = $CMDB_MAC - Model = $CMDB_model - Serial = $CMDB_serial + MAC = 'No DNS Entry' + Model = 'No DNS Entry' + Serial = 'No DNS Entry' #Comment = $comment Color = 'No DNS Entry' Trays = 'No DNS Entry' PageCount = 'No DNS Entry' - 'CMDB POA' = $CMDB_POA - 'CMDB AssetTag' = $CMDB_AssetTag - 'CMDB Location' = $CMDB_Location } $obj = New-Object -TypeName PSObject -Property $props $snmp.close() diff --git a/Public/Get-PC.ps1 b/Public/Get-PC.ps1 index c92dd83..c817143 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 @@ -40,6 +40,7 @@ Function Get-PC { -Apps | shows the installed applications on the computer -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 -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 @@ -48,6 +49,7 @@ Function Get-PC { -InstallNet35 | installs .Net 3.5 -LogOffUser | remotely logs off user -Monitor | monitors computers for changes in status + -NextPrinterName | generates next open printer name -Orion | opens orion to the mac address of the pc -PCCleanup | removes temp files and inactive user profiles -PCReboot | reboots computer @@ -61,6 +63,7 @@ Function Get-PC { -SHSPrinterweb | pulls data about a printer and opens web interface and orion -SHSUser | get data about a user from AD, can accept username or employee number -Tableview | output the results in a table + -UninstallProgram | remotely uninstall a program from a pc -Usb | shows installed usb devices -UserProfileBackup | backups and restores user profiles -ViewerRemote | remote into the computer using RemoteViewer @@ -85,6 +88,7 @@ Function Get-PC { [Switch]$Apps, [Switch]$AppDiff, [Switch]$Bypass, + [Switch]$ClearCCMCache, [switch]$Devices, [Switch]$EventLog, [switch]$Excel, @@ -103,8 +107,8 @@ Function Get-PC { [Switch]$PCRename, [Switch]$Quiet, [Switch]$RemoteDesktopApp, - [Switch]$Resources, [Switch]$ResetRepository, + [Switch]$Resources, [Switch]$PrinterPurge, [Switch]$SCCM, [Switch]$SHSPrinter, @@ -139,6 +143,12 @@ Function Get-PC { break } + if ($Jobsprinters) { + #runs the printer query as a set of jobs + $outPutArray = Get-PCBatchJob($ComputerName) -printers + Write-Output $outPutArray + return + } $getPCComputers = @() #List of computers that will get a batch query $outPutArray = @() #For use near the end of the script to output to users screen in a specified format @@ -155,7 +165,7 @@ Function Get-PC { $oldcomp = $comp $comp,$msg = Get-Hostname $comp - if ($msg) { + if ($msg -and -not $SHSPrinter) { Write-Host "`n$msg" -ForegroundColor Red $props = [Ordered]@{ @@ -459,6 +469,16 @@ Function Get-PC { Get-FileSystem $comp continue } + + if ($ClearCCMCache) { + + if ($compStatus -ne 'Online') { + Write-Warning "$comp is $compStatus unable to proccess command" + break + } + Invoke-ClearCCMCache $comp + break + } #Will log off the current logged in user for the designated PC #Adapted from Josh Gobens Logoff Script diff --git a/patchnotes.txt b/patchnotes.txt index ecdd88b..5764aeb 100644 --- a/patchnotes.txt +++ b/patchnotes.txt @@ -1,3 +1,8 @@ +Patch: 2024-07-26 +-Refactors +-Update BatchInvokes to utilize jobs for up to 4x speedup +-Add ClearCCMCache + Patch: 2024-07-15 -Add UninstallProgram to uninstall a program from the target pc -Fix Apps to report version and publisher correctly