From c4f3efa30bba78fd6369fd2a01d48b63011dab27 Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Thu, 13 Feb 2025 14:41:15 -0800 Subject: [PATCH 1/7] Apps only queries sccm when workstation isn't online and BatchInvokes now queries CMDB instead of returning empty PC --- Get-PC/Private/AppDiff.ps1 | 3 +- Get-PC/Private/Apps.ps1 | 74 +++++++++++-------------------- Get-PC/Private/SCCMQueryBlock.ps1 | 26 +---------- Get-PC/Public/Get-PC.ps1 | 4 +- 4 files changed, 31 insertions(+), 76 deletions(-) diff --git a/Get-PC/Private/AppDiff.ps1 b/Get-PC/Private/AppDiff.ps1 index ef8b5dc..cc52e4b 100644 --- a/Get-PC/Private/AppDiff.ps1 +++ b/Get-PC/Private/AppDiff.ps1 @@ -13,13 +13,14 @@ function Get-AppDiff { param( [Parameter(Mandatory)] $pc, + $CompStatus = $offline, $TableView = $false ) # Compares a pc's apps with a list of expected apps to see if the pc has any # extra apps that we need to consider downloading - $apps = Get-Apps $pc + $apps = Get-Apps $pc $CompStatus Write-Progress -Activity "Filtering out standard apps from $pc" -Status 'Removing version numbers and loading reference' -PercentComplete 10 -ParentId 1 $apps = Remove-Version $apps # Open example file diff --git a/Get-PC/Private/Apps.ps1 b/Get-PC/Private/Apps.ps1 index 81b64c7..f6d8f4d 100644 --- a/Get-PC/Private/Apps.ps1 +++ b/Get-PC/Private/Apps.ps1 @@ -1,58 +1,34 @@ -Function Get-Apps($ComputerName, $TableView) { +# Assumes 64 bit system, registry keys may be different on 32 bit systems +Function Get-Apps($ComputerName, $CompStatus, $TableView) { + $32RegPath = 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' + $64RegPath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' - Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Querying SCCM apps' -PercentComplete 10 -ParentId 1 - $86apps, $64apps = Get-SCCM_Apps $ComputerName - - Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Querying local apps' -PercentComplete 30 -ParentId 1 - #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 { - #Checks if pc is online so Invoke doesn't hang on offline pc - if (Test-Connection -ComputerName $ComputerName -Count 1) { - $localapps = Invoke-Command -ComputerName $ComputerName -SessionOption $(New-PSSessionOption -MaxConnectionRetryCount 1 -NoMachineProfile) -ScriptBlock { - Get-Package -ProviderName Programs -IncludeWindowsInstaller | + if ($CompStatus -eq "Online") { + Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Querying local apps' -PercentComplete 30 -ParentId 1 + $sblock = { + $apps = Get-ItemProperty $32RegPath | Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru | - Select-Object @{N='DisplayName';E={$_.Name}},* | - Sort-Object -Property DisplayName - } + Add-Member -NotePropertyName x86/x64 -NotePropertyValue 32 -PassThru + $apps += Get-ItemProperty $64RegPath | + Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru | + Add-Member -NotePropertyName x86/x64 -NotePropertyValue 64 -PassThru + $apps += Get-Package | + Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru + $apps | Sort-Object 'x86/x64',DisplayName -Unique | ForEach-Object { $_.PSObject.TypeNames.Insert(0, 'GetPC.App'); $_ } + } + #Checks if local computer + if ($ComputerName -eq $env:COMPUTERNAME) { + $apps = Invoke-Command -ScriptBlock $sblock + } else { + $apps = Invoke-Command -ComputerName $ComputerName -SessionOption $(New-PSSessionOption -MaxConnectionRetryCount 1 -NoMachineProfile) -ScriptBlock $sblock } - } - - Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Combining apps from SCCM' -PercentComplete 50 -ParentId 1 - $out = $86apps + $64apps - $apps = @() - foreach ($item in $out) { - $a = New-Object -TypeName PSCustomObject - $a.PSObject.TypeNames.Insert(0, 'GetPC.App') - Copy-Property -From $item -To $a - $apps += $a - } - - # Blank entry for visual break - $a = [PSCustomObject]@{ - DisplayName = "" - } - $a.PSObject.TypeNames.Insert(0, 'GetPC.App') - $apps += $a - - Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Combining apps from local query' -PercentComplete 75 -ParentId 1 - # Grab apps that are only returned by local query - if ($out) { - $localOnly = Compare-Object $localapps $out -Property DisplayName -PassThru | Where-Object {$_.SideIndicator -eq '<='} } else { - $localOnly = $localapps - } - foreach ($item in $localOnly) { - $a = New-Object -TypeName PSCustomObject - $a.PSObject.TypeNames.Insert(0, 'GetPC.App') - Copy-Property -From $item -To $a - $apps += $a + Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Querying SCCM apps' -PercentComplete 10 -ParentId 1 + $86apps, $64apps = Get-SCCM_Apps $ComputerName + $apps = ($86apps + $64apps) | Sort-Object 'x86/x64',DisplayName -Unique | ForEach-Object { $_.PSObject.TypeNames.Insert(0, 'GetPC.App'); $_ } } + if ($TableView) { $apps | Out-GridView -Title "Get-PC Apps - $ComputerName" } diff --git a/Get-PC/Private/SCCMQueryBlock.ps1 b/Get-PC/Private/SCCMQueryBlock.ps1 index 0f83d64..c18cdd8 100644 --- a/Get-PC/Private/SCCMQueryBlock.ps1 +++ b/Get-PC/Private/SCCMQueryBlock.ps1 @@ -42,30 +42,8 @@ $Headers = @{ $FindLastHardwareScanSCCM = Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $FindLastHardwareScanQuery | Select-Object -ExpandProperty LastHardwareScan 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 + Write-Progress -Activity "Getting SCCM data for $comp" -Completed + return } $Year = $FindLastHardwareScanSCCM.substring(0,4) diff --git a/Get-PC/Public/Get-PC.ps1 b/Get-PC/Public/Get-PC.ps1 index 06a405f..5da0561 100644 --- a/Get-PC/Public/Get-PC.ps1 +++ b/Get-PC/Public/Get-PC.ps1 @@ -531,12 +531,12 @@ begin { #Pulls a list of installed programs from SCCM and Get-Package if ($Apps) { - Get-Apps $comp $TableView + Get-Apps $comp $compStatus $TableView continue } if ($AppDiff) { - Get-AppDiff $comp $TableView + Get-AppDiff $comp $compStatus $TableView continue } From e798c0d68651ad4b9ecbde37a8c6726467faa927 Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Thu, 13 Feb 2025 14:48:36 -0800 Subject: [PATCH 2/7] Tidied up apps --- Get-PC/Private/Apps.ps1 | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/Get-PC/Private/Apps.ps1 b/Get-PC/Private/Apps.ps1 index f6d8f4d..2dd97bf 100644 --- a/Get-PC/Private/Apps.ps1 +++ b/Get-PC/Private/Apps.ps1 @@ -1,11 +1,10 @@ # Assumes 64 bit system, registry keys may be different on 32 bit systems Function Get-Apps($ComputerName, $CompStatus, $TableView) { - $32RegPath = 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' - $64RegPath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' - if ($CompStatus -eq "Online") { Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Querying local apps' -PercentComplete 30 -ParentId 1 $sblock = { + $32RegPath = 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' + $64RegPath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' $apps = Get-ItemProperty $32RegPath | Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru | Add-Member -NotePropertyName x86/x64 -NotePropertyValue 32 -PassThru @@ -14,13 +13,14 @@ Function Get-Apps($ComputerName, $CompStatus, $TableView) { Add-Member -NotePropertyName x86/x64 -NotePropertyValue 64 -PassThru $apps += Get-Package | Add-Member -NotePropertyName Computer -NotePropertyValue $env:ComputerName -PassThru - $apps | Sort-Object 'x86/x64',DisplayName -Unique | ForEach-Object { $_.PSObject.TypeNames.Insert(0, 'GetPC.App'); $_ } + $apps | Sort-Object 'x86/x64',DisplayName -Unique } #Checks if local computer if ($ComputerName -eq $env:COMPUTERNAME) { - $apps = Invoke-Command -ScriptBlock $sblock + $apps = Invoke-Command -ScriptBlock $sblock | ForEach-Object { $_.PSObject.TypeNames.Insert(0, 'GetPC.App'); $_ } } else { - $apps = Invoke-Command -ComputerName $ComputerName -SessionOption $(New-PSSessionOption -MaxConnectionRetryCount 1 -NoMachineProfile) -ScriptBlock $sblock + $apps = Invoke-Command -ComputerName $ComputerName -SessionOption $(New-PSSessionOption -MaxConnectionRetryCount 1 -NoMachineProfile) -ScriptBlock $sblock | + Select-Object -Property * -ExcludeProperty PSComputerName | ForEach-Object { $_.PSObject.TypeNames.Insert(0, 'GetPC.App'); $_ } } } else { Write-Progress -Activity "Getting apps for $ComputerName" -Status 'Querying SCCM apps' -PercentComplete 10 -ParentId 1 @@ -36,11 +36,4 @@ Function Get-Apps($ComputerName, $CompStatus, $TableView) { Write-Output $apps } Write-Progress -Activity "Getting apps for $ComputerName" -Completed -} -function Copy-Property ($From, $To) { - - $properties = Get-Member -InputObject $From -MemberType NoteProperty - foreach ($p in $properties) { - $To | Add-Member -MemberType NoteProperty -Name $p.Name -Value $From.$($p.Name) -Force - } } \ No newline at end of file From 3397a29df4ed5a47083fcc2d24c938b8643efe6a Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Thu, 13 Feb 2025 15:04:45 -0800 Subject: [PATCH 3/7] Exposed HostnamesByPrinter to help --- Get-PC/Public/Get-PC.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Get-PC/Public/Get-PC.ps1 b/Get-PC/Public/Get-PC.ps1 index 5da0561..d2c3380 100644 --- a/Get-PC/Public/Get-PC.ps1 +++ b/Get-PC/Public/Get-PC.ps1 @@ -70,6 +70,7 @@ Function Get-PC { -Excel | exports collected data to csv and opens it with excel -Filesystem | access the file system -GPUpdate | runs a gpupdate + -HostnamesByPrinter | grabs all hostnames that have the requested printer installed on it -InstallNet35 | installs .Net 3.5 -LogOffUser | remotely logs off user -Monitor | monitors computers for changes in status From 69f31460702714e3e81437027057b1f144be2b41 Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Thu, 13 Feb 2025 15:21:11 -0800 Subject: [PATCH 4/7] Tidied up SHSPrinter in preparation for making it a job --- Get-PC/Private/SHSPrinter.ps1 | 55 ++++++++--------------------------- 1 file changed, 12 insertions(+), 43 deletions(-) diff --git a/Get-PC/Private/SHSPrinter.ps1 b/Get-PC/Private/SHSPrinter.ps1 index 80c1dcb..7111aef 100644 --- a/Get-PC/Private/SHSPrinter.ps1 +++ b/Get-PC/Private/SHSPrinter.ps1 @@ -13,15 +13,24 @@ function Get-SHSPrinter { [string]$printer ) - Write-Progress -Activity "Getting printer details for $name" -Status 'Getting IP Address' -PercentComplete 10 -ParentId 1 + Write-Progress -Activity "Getting printer details for $printer" -Status 'Getting IP Address' -PercentComplete 10 -ParentId 1 $snmp = New-Object -ComObject olePrn.OleSNMP #Gets the printer ip and full domain name - $result = Get-PrinterIP $printer + $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 } + } + } #CMDB Data - Write-Progress -Activity "Getting printer details for $name" -Status 'Getting CMDB data' -PercentComplete 20 -ParentId 1 + Write-Progress -Activity "Getting printer details for $printer" -Status 'Getting CMDB data' -PercentComplete 20 -ParentId 1 # $cmdbRecord = Get-LANDeskCMDBItem -Name $printer $cmdbRecord = Search-ISMBO -BO cis -filter "Name eq '$Printer'" -RawFilter @@ -409,47 +418,7 @@ function Get-PrinterIP { [parameter(ValueFromPipeline)] [string]$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($result -eq $null){ - $hit = $false - foreach ($domain in $domains) { - $search = "$printer$domain" - $result = Resolve-DnsName $search -ErrorAction SilentlyContinue - if($result -ne $null){ - $hit = $true - $name = $result.Name - $ip = $result.IPAddress - - - } - - } - - if($result -eq $null){ - if($hit -eq $false){ - $ip = $null - $name = $null - } - } - } - else{ - $name = $result.Name - $ip = $result.IPAddress - - } - - $props = [ordered]@{Hostname=$printer - IP=$ip - Path=$name - } - $obj = New-Object -TypeName PSObject -Property $props - - return $obj - - } function Start-SHSPrinterWeb { From 31c72c9a6bdd34dd6805c5bd902501b14af9743c Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Thu, 13 Feb 2025 15:54:11 -0800 Subject: [PATCH 5/7] Fixed jobsprinters --- Get-PC/Private/SCCMQueryBlock.ps1 | 4 +- Get-PC/Private/SHSPrinter.ps1 | 647 +++++++++++++++--------------- 2 files changed, 323 insertions(+), 328 deletions(-) diff --git a/Get-PC/Private/SCCMQueryBlock.ps1 b/Get-PC/Private/SCCMQueryBlock.ps1 index c18cdd8..f1f0b64 100644 --- a/Get-PC/Private/SCCMQueryBlock.ps1 +++ b/Get-PC/Private/SCCMQueryBlock.ps1 @@ -226,7 +226,7 @@ $Headers = @{ $cmdbData = $Query.Value } else { $cmdbData = @{ - Loc = "CMDB Mismatch!" + SHS_LocationDetails = "CMDB Mismatch!" Status = "CMDB Mismatch!" } } @@ -234,7 +234,7 @@ $Headers = @{ #Write-Host $_.Exception.Message #Write-Warning "Failed querying Spark!" $cmdbData = @{ - Loc = "Failed querying Spark!" + SHS_LocationDetails = "Failed querying Spark!" Status = "Failed querying Spark!" } } diff --git a/Get-PC/Private/SHSPrinter.ps1 b/Get-PC/Private/SHSPrinter.ps1 index 7111aef..9a0fe05 100644 --- a/Get-PC/Private/SHSPrinter.ps1 +++ b/Get-PC/Private/SHSPrinter.ps1 @@ -13,6 +13,15 @@ function Get-SHSPrinter { [string]$printer ) +# Spark connection params +$Tenant = 'https://samaritanhealth-amc.ivanticloud.com' +$Headers = @{ + "Content-Type" = "application/json" + "Authorization" = 'rest_api_key=EB68123D62F8489295C807353C92D75B' + "Accept" = "*/*" + "Accept-Encoding" = "gzip, deflate, br" +} + Write-Progress -Activity "Getting printer details for $printer" -Status 'Getting IP Address' -PercentComplete 10 -ParentId 1 $snmp = New-Object -ComObject olePrn.OleSNMP @@ -32,7 +41,26 @@ function Get-SHSPrinter { Write-Progress -Activity "Getting printer details for $printer" -Status 'Getting CMDB data' -PercentComplete 20 -ParentId 1 # $cmdbRecord = Get-LANDeskCMDBItem -Name $printer - $cmdbRecord = Search-ISMBO -BO cis -filter "Name eq '$Printer'" -RawFilter + $timeout = if ($SparkQueryTimeoutSec) {$SparkQueryTimeoutSec} else {5} + $uri = "$Tenant/api/odata/businessobject/cis`?`$filter=Name eq '$printer'&`$top=1&`$skip=0" + try { + $Query = Invoke-RestMethod -Method GET -uri $uri -headers $Headers -TimeoutSec $timeout + if ($Query) { + $cmdbData = $Query.Value + } else { + $cmdbData = @{ + SHS_LocationDetails = "CMDB Mismatch!" + Status = "CMDB Mismatch!" + } + } + } catch { + #Write-Host $_.Exception.Message + #Write-Warning "Failed querying Spark!" + $cmdbData = @{ + SHS_LocationDetails = "Failed querying Spark!" + Status = "Failed querying Spark!" + } + } $LocationConstructors = @( "SHS_AssetLocality", @@ -42,275 +70,250 @@ function Get-SHSPrinter { "SHS_LocationDetails" ) - $LocationData = Foreach ($Loc in $LocationConstructors) { + $LocationData = Foreach($Loc in $LocationConstructors){ - if ($Loc -eq 'SHS_Floor') { - $(if ($cmdbRecord.$Loc -match '-') { $cmdbRecord.$Loc.split('-')[-1] + " Floor" } else { $cmdbRecord.$Loc }) - } - elseif (![string]::IsNullOrEmpty($cmdbRecord.$Loc)) { - $cmdbRecord.$Loc + if ($Loc -eq 'SHS_Floor'){ + $(if ($cmdbData.$Loc -match '-'){$cmdbData.$Loc.split('-')[-1] + " Floor"} else{$cmdbData.$Loc}) + } elseif (![string]::IsNullOrEmpty($cmdbData.$Loc)){ + $cmdbData.$Loc } } $LocationData = $LocationData -join ' | ' - # $locationData = $cmdbRecord.SHS_AssetLocality + " | " + $cmdbRecord.ivnt_Location + " | " + + " | " + $cmdbRecord.SHS_Department + " | " + $cmdbRecord.SHS_LocationDetails - # 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 - + if ($cmdbData) { ### Spark Properties - $CMDB_POA = $cmdbRecord.SHS_POANumber - $CMDB_AssetTag = $cmdbRecord.AssetTag + $CMDB_POA = $cmdbData.SHS_POANumber + $CMDB_AssetTag = $cmdbData.AssetTag $CMDB_Location = $locationData - $CMDB_MAC = $cmdbRecord.MACAddress - $CMDB_model = $cmdbRecord.Model - $CMDB_serial = $cmdbRecord.SerialNumber - $CMDB_IP = $cmdbRecord.IPAddress + $CMDB_MAC = $cmdbData.MACAddress + $CMDB_model = $cmdbData.Model + $CMDB_serial = $cmdbData.SerialNumber + $CMDB_IP = $cmdbData.IPAddress + $CMDB_Status = $cmdbData.Status + } + + if ($null -eq $result.IPAddress) { + if ($CMDB_IP) { + $offlineIP = 'CMDB IP - ' + $CMDB_IP + } + else { + $offlineIP = 'No DNS Entry' + } + $props = [Ordered]@{ + Machine = $printer + Status = 'No DNS Entry' + IP = $offlineIP + DomainName = 'No DNS Entry' + MAC = $CMDB_MAC + Model = $CMDB_model + Serial = $CMDB_serial + #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 + 'CMDB Status' = $CMDB_Status + } + $obj = New-Object -TypeName PSObject -Property $props + return $obj + } + + Write-Progress -Activity "Getting printer details for $name" -Status 'Connecting to printer' -PercentComplete 30 -ParentId 1 + + $printerip = $result.IPAddress + $null = $result.Name -match '[^.]*\.(.*)' + $domainName = $Matches[1] + + #checks to see if the printer is online + $online = Test-Connection $printerip -ErrorAction SilentlyContinue + + if (-not $online) { + $status = "Offline" + $MAC = $CMDB_MAC + $model = $CMDB_model + $serial = $CMDB_serial + $color = "Offline" + $trays = "Offline" + $pagecount = "Offline" } 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*" - } + #opens snmp connection to the printer + $snmp.open($printerip, 'public', 2, 3000) - if ($null -ne $result.IP) { + Write-Progress -Activity "Getting printer details for $name" -Status 'Querying for MAC address' -PercentComplete 40 -ParentId 1 + # Start of MAC + $pMAC = $SNMP.get(".1.3.6.1.2.1.2.2.1.6.2") + $MAC = [System.Text.Encoding]::Default.GetBytes($PMac) | ForEach-Object { + $_.ToString('X2') + } + $MAC = $MAC -join ':' + #End of MAC + + Write-Progress -Activity "Getting printer details for $name" -Status 'Querying for model' -PercentComplete 50 -ParentId 1 + # MODEL + try { $model = $snmp.Get('.1.3.6.1.2.1.25.3.2.1.3.1') } catch { $model = $null } - Write-Progress -Activity "Getting printer details for $name" -Status 'Connecting to printer' -PercentComplete 30 -ParentId 1 - - $printerip = $result.IP - $domainName = $result.Path - - #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) - - Write-Progress -Activity "Getting printer details for $name" -Status 'Querying for MAC address' -PercentComplete 40 -ParentId 1 - # Start of MAC - $pMAC = $SNMP.get(".1.3.6.1.2.1.2.2.1.6.2") - $MAC = [System.Text.Encoding]::Default.GetBytes($PMac) | ForEach-Object { - $_.ToString('X2') - } - $MAC = $MAC -join ':' - #End of MAC - - Write-Progress -Activity "Getting printer details for $name" -Status 'Querying for model' -PercentComplete 50 -ParentId 1 - # MODEL - try { $model = $snmp.Get('.1.3.6.1.2.1.25.3.2.1.3.1') } catch { $model = $null } + # IF IT HAS A MODEL NAME... + if ($model) { - # IF IT HAS A MODEL NAME... - if ($model) { - - Write-Progress -Activity "Getting printer details for $name" -Status 'Querying for color' -PercentComplete 60 -ParentId 1 - # COLOR - # might want to check on this one - try { if ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.2') -match 'Toner|Cartridge|ink') { $color = 'Yes' } else { $color = 'No' } } catch { $color = 'No' } + Write-Progress -Activity "Getting printer details for $name" -Status 'Querying for color' -PercentComplete 60 -ParentId 1 + # COLOR + # might want to check on this one + try { if ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.2') -match 'Toner|Cartridge|ink') { $color = 'Yes' } else { $color = 'No' } } catch { $color = 'No' } - Write-Progress -Activity "Getting printer details for $name" -Status 'Querying for trays' -PercentComplete 70 -ParentId 1 - # TRAYS - try { $trays = $($snmp.GetTree('.1.3.6.1.2.1.43.8.2.1.13') | ? { $_ -notlike 'print*' }) -join ';' } catch { $trays = $null } + Write-Progress -Activity "Getting printer details for $name" -Status 'Querying for trays' -PercentComplete 70 -ParentId 1 + # TRAYS + try { $trays = $($snmp.GetTree('.1.3.6.1.2.1.43.8.2.1.13') | ? { $_ -notlike 'print*' }) -join ';' } catch { $trays = $null } - Write-Progress -Activity "Getting printer details for $name" -Status 'Querying for serial numbers' -PercentComplete 80 -ParentId 1 - # SERIAL - try { $serial = $snmp.Get('.1.3.6.1.2.1.43.5.1.1.17.1') } catch { $serial = $null } - - Write-Progress -Activity "Getting printer details for $name" -Status 'Querying for page count' -PercentComplete 90 -ParentId 1 - #PAGECOUNT - try { $pagecount = $snmp.Get('.1.3.6.1.2.1.43.10.2.1.4.1.1') } catch { $page = $null } + Write-Progress -Activity "Getting printer details for $name" -Status 'Querying for serial numbers' -PercentComplete 80 -ParentId 1 + # SERIAL + try { $serial = $snmp.Get('.1.3.6.1.2.1.43.5.1.1.17.1') } catch { $serial = $null } + + Write-Progress -Activity "Getting printer details for $name" -Status 'Querying for page count' -PercentComplete 90 -ParentId 1 + #PAGECOUNT + try { $pagecount = $snmp.Get('.1.3.6.1.2.1.43.10.2.1.4.1.1') } catch { $page = $null } - Write-Progress -Activity "Getting printer details for $name" -Status 'Querying for model features' -PercentComplete 100 -ParentId 1 -Id 2 - ##### FEATURES, NAME - switch -Regex ($model) { - '^sharp' { - try { $status = $snmp.Get('.1.3.6.1.2.1.43.18.1.1.8.1.1') } catch { $status = $null } - # Start of MAC - $pMAC = $SNMP.get(".1.3.6.1.4.1.11.2.4.3.1.23.0") - - $MAC = [System.Text.Encoding]::Default.GetBytes($PMac) | ForEach-Object { - $_.ToString('X2') - } - $MAC = $MAC -join ':' - #End of MAC + Write-Progress -Activity "Getting printer details for $name" -Status 'Querying for model features' -PercentComplete 100 -ParentId 1 -Id 2 + ##### FEATURES, NAME + switch -Regex ($model) { + '^sharp' { + try { $status = $snmp.Get('.1.3.6.1.2.1.43.18.1.1.8.1.1') } catch { $status = $null } + # Start of MAC + $pMAC = $SNMP.get(".1.3.6.1.4.1.11.2.4.3.1.23.0") + + $MAC = [System.Text.Encoding]::Default.GetBytes($PMac) | ForEach-Object { + $_.ToString('X2') } - '^zebra' { - Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for name' -PercentComplete 10 -ParentId 2 - try { $name = $snmp.Get('.1.3.6.1.4.1.10642.1.4.0').toupper() } catch { $name = $null } - Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for model' -PercentComplete 30 -ParentId 2 - try { $model = $snmp.Get('.1.3.6.1.4.1.10642.200.19.7.0').toupper() } catch { $model = $null } - Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for MAC address' -PercentComplete 50 -ParentId 2 - try { $MAC = $snmp.Get('.1.3.6.1.4.1.10642.20.10.20.10.2.1.5.2').toupper() } catch { $MAC = $null } - Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for serial number' -PercentComplete 70 -ParentId 2 - try { $serial = $snmp.Get('.1.3.6.1.4.1.10642.200.19.5.0') } catch { $serial = $null } - # try { $status = $snmp.Get('.1.3.6.1.4.1.10642.200.4.1.0') } catch { $status = $null } - # Zebra GK420 - Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for IP assignment mode' -PercentComplete 80 -ParentId 2 - try { $ipconfig = "($($snmp.Get('.1.3.6.1.4.1.10642.200.50.1.1.5.0')))" } catch { $ipconfig = $null } - # Zebra ZD421 - if (!$ipconfig) { - Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for IP assignment mode (2nd attempt)' -PercentComplete 85 -ParentId 2 - try { $ipconfig = $snmp.Get('.1.3.6.1.4.1.10642.20.10.20.15.2.1.5.2') } catch { $ipconfig = $null } - $ipconfig = switch ($ipconfig) { - 1 {'(All)'} - 2 {'(GLEANING ONLY)'} - 3 {'(RARP)'} - 4 {'(BOOTP)'} - 5 {'(DHCP)'} - 6 {'(DHCP AND BOOTP)'} - 7 {'(PERMANENT)'} - } - } - $model = "Zebra $model" - Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for status' -PercentComplete 90 -ParentId 2 - #STATUS - $uri = $domainName - $html = Invoke-WebRequest -uri $uri - $raw = $html.rawcontent - $raw -match '([A-Z])\w+<.F' | Out-Null - $status = ($Matches[0] -split '<')[0] - #split off error condition - $raw -match 'RED>.+' | Out-Null - $split = $Matches[0] -split '>' - $err = $split[1] -split '<' - $status = $status + ' ' + $err[0] - - Write-Progress -Activity "Getting zebra features from $name" -Completed - } - '^lexmark' { - Write-Progress -Activity "Getting lexmark features from $name" -Status 'Querying for name' -PercentComplete 50 -ParentId 2 - try { $name = $snmp.Get('.1.3.6.1.4.1.641.1.5.7.6.0').toupper() } catch { $name = $null } - Write-Progress -Activity "Getting lexmark features from $name" -Completed - } - '^ricoh' { - Write-Progress -Activity "Getting ricoh features from $name" -Status 'Querying for name' -PercentComplete 50 -ParentId 2 - try { $name = $snmp.Get('.1.3.6.1.4.1.367.3.2.1.7.3.5.1.1.2.1.1').toupper() } catch { $name = $null } - Write-Progress -Activity "Getting ricoh features from $name" -Completed - } - '^hp' { - Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for name' -PercentComplete 5 -ParentId 2 - try { $name = $snmp.Get('.1.3.6.1.4.1.11.2.4.3.5.46.0').toupper() } catch { $name = $null } - Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for status' -PercentComplete 10 -ParentId 2 - try { $status = $snmp.Get('.1.3.6.1.4.1.11.2.3.9.1.1.3.0') } catch { $status = $null } - Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for IP configuration' -PercentComplete 10 -ParentId 2 - try { $ipconfig = $snmp.Get('.1.3.6.1.4.1.11.2.4.3.5.1.0') } catch { $status = $null } + $MAC = $MAC -join ':' + #End of MAC + } + '^zebra' { + Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for name' -PercentComplete 10 -ParentId 2 + try { $name = $snmp.Get('.1.3.6.1.4.1.10642.1.4.0').toupper() } catch { $name = $null } + Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for model' -PercentComplete 30 -ParentId 2 + try { $model = $snmp.Get('.1.3.6.1.4.1.10642.200.19.7.0').toupper() } catch { $model = $null } + Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for MAC address' -PercentComplete 50 -ParentId 2 + try { $MAC = $snmp.Get('.1.3.6.1.4.1.10642.20.10.20.10.2.1.5.2').toupper() } catch { $MAC = $null } + Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for serial number' -PercentComplete 70 -ParentId 2 + try { $serial = $snmp.Get('.1.3.6.1.4.1.10642.200.19.5.0') } catch { $serial = $null } + # try { $status = $snmp.Get('.1.3.6.1.4.1.10642.200.4.1.0') } catch { $status = $null } + # Zebra GK420 + Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for IP assignment mode' -PercentComplete 80 -ParentId 2 + try { $ipconfig = "($($snmp.Get('.1.3.6.1.4.1.10642.200.50.1.1.5.0')))" } catch { $ipconfig = $null } + # Zebra ZD421 + if (!$ipconfig) { + Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for IP assignment mode (2nd attempt)' -PercentComplete 85 -ParentId 2 + try { $ipconfig = $snmp.Get('.1.3.6.1.4.1.10642.20.10.20.15.2.1.5.2') } catch { $ipconfig = $null } $ipconfig = switch ($ipconfig) { - 1 { '(manual)' } #manual-one - 2 { '(bootp)' } #bootp-two - 3 { '(manual)' } #manual-three - 4 { '(bootp)' } #bootp-four - 5 { '(dhcp)' } #dhcp - 6 { '' } #not-configured - 7 { '(default)' } #default-config - 8 { '(rarp)' } #rarp - 9 { '' } #read-only - 10 { '(auto-ip)' } #auto-ip + 1 {'(All)'} + 2 {'(GLEANING ONLY)'} + 3 {'(RARP)'} + 4 {'(BOOTP)'} + 5 {'(DHCP)'} + 6 {'(DHCP AND BOOTP)'} + 7 {'(PERMANENT)'} } - if ($MAC -eq '') { - Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for MAC Address' -PercentComplete 15 -ParentId 2 - $pMAC = $snmp.Get('.1.3.6.1.4.1.11.2.4.3.1.12.1.2.5') - $MAC = ($pMAC -split " ")[-1] - $MAC = ($MAC -replace '(..)', '$1:').trim(':') - - } - #TONER - <# - HP Maintenance Kit Cur: 1.3.6.1.2.1.43.11.1.1.9.1.2 - HP Maintenance Kit Max: 1.3.6.1.2.1.43.11.1.1.8.1.2 - HP Toner Cur: 1.3.6.1.2.1.43.11.1.1.9.1.1 - HP Toner Max: 1.3.6.1.2.1.43.11.1.1.8.1.1 - #> - Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for toner color' -PercentComplete 20 -ParentId 2 - try { $tonerColor = ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.1') -split ' ')[0] } catch { $tonerColor = $null } - Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for toner level' -PercentComplete 25 -ParentId 2 - try { $tonerLvl = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.9.1.1') } catch { $tonerLvl = $null } - try { $tonerMax = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.8.1.1') } catch { $tonerMax = $null } - try { $toner = $tonerLvl / $tonerMax } catch { $toner = $null } - [int]$toner = $toner * 100 - $supplies = "$tonerColor" + ":$toner% " - if ($color -eq 'Yes') { - Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for toner color levels' -PercentComplete 35 -ParentId 2 - try { $tonerColor = ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.2') -split ' ')[0] } catch { $tonerColor = $null } - try { $tonerLvl = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.9.1.2') } catch { $tonerLvl = $null } - try { $tonerMax = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.8.1.2') } catch { $tonerMax = $null } - try { $toner = $tonerLvl / $tonerMax * 100 } catch { $toner = $null } - $supplies += "$tonerColor" + ":$toner% " + } + $model = "Zebra $model" + Write-Progress -Activity "Getting zebra features from $name" -Status 'Querying for status' -PercentComplete 90 -ParentId 2 + #STATUS + $uri = $domainName + $html = Invoke-WebRequest -uri $uri + $raw = $html.rawcontent + $raw -match '([A-Z])\w+<.F' | Out-Null + $status = ($Matches[0] -split '<')[0] + #split off error condition + $raw -match 'RED>.+' | Out-Null + $split = $Matches[0] -split '>' + $err = $split[1] -split '<' + $status = $status + ' ' + $err[0] - Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for toner color levels' -PercentComplete 50 -ParentId 2 - try { $tonerColor = ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.3') -split ' ')[0] } catch { $tonerColor = $null } - try { $tonerLvl = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.9.1.3') } catch { $tonerLvl = $null } - try { $tonerMax = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.8.1.3') } catch { $tonerMax = $null } - try { $toner = $tonerLvl / $tonerMax * 100 } catch { $toner = $null } - $supplies += "$tonerColor" + ":$toner% " + Write-Progress -Activity "Getting zebra features from $name" -Completed + } + '^lexmark' { + Write-Progress -Activity "Getting lexmark features from $name" -Status 'Querying for name' -PercentComplete 50 -ParentId 2 + try { $name = $snmp.Get('.1.3.6.1.4.1.641.1.5.7.6.0').toupper() } catch { $name = $null } + Write-Progress -Activity "Getting lexmark features from $name" -Completed + } + '^ricoh' { + Write-Progress -Activity "Getting ricoh features from $name" -Status 'Querying for name' -PercentComplete 50 -ParentId 2 + try { $name = $snmp.Get('.1.3.6.1.4.1.367.3.2.1.7.3.5.1.1.2.1.1').toupper() } catch { $name = $null } + Write-Progress -Activity "Getting ricoh features from $name" -Completed + } + '^hp' { + Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for name' -PercentComplete 5 -ParentId 2 + try { $name = $snmp.Get('.1.3.6.1.4.1.11.2.4.3.5.46.0').toupper() } catch { $name = $null } + Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for status' -PercentComplete 10 -ParentId 2 + try { $status = $snmp.Get('.1.3.6.1.4.1.11.2.3.9.1.1.3.0') } catch { $status = $null } + Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for IP configuration' -PercentComplete 10 -ParentId 2 + try { $ipconfig = $snmp.Get('.1.3.6.1.4.1.11.2.4.3.5.1.0') } catch { $status = $null } + $ipconfig = switch ($ipconfig) { + 1 { '(manual)' } #manual-one + 2 { '(bootp)' } #bootp-two + 3 { '(manual)' } #manual-three + 4 { '(bootp)' } #bootp-four + 5 { '(dhcp)' } #dhcp + 6 { '' } #not-configured + 7 { '(default)' } #default-config + 8 { '(rarp)' } #rarp + 9 { '' } #read-only + 10 { '(auto-ip)' } #auto-ip + } + if ($MAC -eq '') { + Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for MAC Address' -PercentComplete 15 -ParentId 2 + $pMAC = $snmp.Get('.1.3.6.1.4.1.11.2.4.3.1.12.1.2.5') + $MAC = ($pMAC -split " ")[-1] + $MAC = ($MAC -replace '(..)', '$1:').trim(':') + + } + #TONER + <# + HP Maintenance Kit Cur: 1.3.6.1.2.1.43.11.1.1.9.1.2 + HP Maintenance Kit Max: 1.3.6.1.2.1.43.11.1.1.8.1.2 + HP Toner Cur: 1.3.6.1.2.1.43.11.1.1.9.1.1 + HP Toner Max: 1.3.6.1.2.1.43.11.1.1.8.1.1 + #> + Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for toner color' -PercentComplete 20 -ParentId 2 + try { $tonerColor = ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.1') -split ' ')[0] } catch { $tonerColor = $null } + Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for toner level' -PercentComplete 25 -ParentId 2 + try { $tonerLvl = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.9.1.1') } catch { $tonerLvl = $null } + try { $tonerMax = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.8.1.1') } catch { $tonerMax = $null } + try { $toner = $tonerLvl / $tonerMax } catch { $toner = $null } + [int]$toner = $toner * 100 + $supplies = "$tonerColor" + ":$toner% " + if ($color -eq 'Yes') { + Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for toner color levels' -PercentComplete 35 -ParentId 2 + try { $tonerColor = ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.2') -split ' ')[0] } catch { $tonerColor = $null } + try { $tonerLvl = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.9.1.2') } catch { $tonerLvl = $null } + try { $tonerMax = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.8.1.2') } catch { $tonerMax = $null } + try { $toner = $tonerLvl / $tonerMax * 100 } catch { $toner = $null } + $supplies += "$tonerColor" + ":$toner% " - Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for toner color levels' -PercentComplete 65 -ParentId 2 - try { $tonerColor = ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.4') -split ' ')[0] } catch { $tonerColor = $null } - try { $tonerLvl = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.9.1.4') } catch { $tonerLvl = $null } - try { $tonerMax = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.8.1.4') } catch { $tonerMax = $null } - try { $toner = $tonerLvl / $tonerMax * 100 } catch { $toner = $null } - $supplies += "$tonerColor" + ":$toner% " + Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for toner color levels' -PercentComplete 50 -ParentId 2 + try { $tonerColor = ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.3') -split ' ')[0] } catch { $tonerColor = $null } + try { $tonerLvl = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.9.1.3') } catch { $tonerLvl = $null } + try { $tonerMax = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.8.1.3') } catch { $tonerMax = $null } + try { $toner = $tonerLvl / $tonerMax * 100 } catch { $toner = $null } + $supplies += "$tonerColor" + ":$toner% " - Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for maintenance kit status' -PercentComplete 80 -ParentId 2 - try { $supplyName = ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.6') -split ' ')[0] } catch { $tonerColor = $null } - if ($supplyName -contains 'Fuser' -or $supplyName -contains 'Maint') { - try { $supplyPartNumber = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.6') } catch { $supplyPartNumber = $null } - $supplyPartNumber -match '110V-(?.+), ' | Out-Null - $supplyPartNumber = $Matches.Name - try { $mainLvl = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.9.1.6') } catch { $mainLvl = $null } - try { $mainMax = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.8.1.6') } catch { $mainMax = $null } - if ($mainMax -gt 1) { - try { $maintKit = $mainLvl / $mainMax } catch { $maintKit = $null } - [int]$maintKit = $maintKit * 100 - - if ($null -ne $maintKit) { - $supplies += "| $supplyName" + ":$maintKit%[$supplyPartNumber]" - } - } - } - else { - try { $supplyName = ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.5') -split ' ')[1] } catch { $tonerColor = $null } - try { $supplyPartNumber = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.5') } catch { $supplyPartNumber = $null } - $supplyPartNumber -match '110V-(?.+), ' | Out-Null - $supplyPartNumber = $Matches.Name - try { $mainLvl = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.9.1.5') } catch { $mainLvl = $null } - try { $mainMax = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.8.1.5') } catch { $mainMax = $null } - if ($mainMax -gt 1) { - try { $maintKit = $mainLvl / $mainMax } catch { $maintKit = $null } - [int]$maintKit = $maintKit * 100 - - if ($null -ne $maintKit) { - $supplies += "| $supplyName" + ":$maintKit%[$supplyPartNumber]" - } - } + Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for toner color levels' -PercentComplete 65 -ParentId 2 + try { $tonerColor = ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.4') -split ' ')[0] } catch { $tonerColor = $null } + try { $tonerLvl = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.9.1.4') } catch { $tonerLvl = $null } + try { $tonerMax = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.8.1.4') } catch { $tonerMax = $null } + try { $toner = $tonerLvl / $tonerMax * 100 } catch { $toner = $null } + $supplies += "$tonerColor" + ":$toner% " - } - } - else { - Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for maintenance kit status' -PercentComplete 80 -ParentId 2 - try { $supplyName = ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.2') -split ' ')[0] } catch { $supplyName = $null } - try { $supplyPartNumber = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.2') } catch { $supplyPartNumber = $null } + Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for maintenance kit status' -PercentComplete 80 -ParentId 2 + try { $supplyName = ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.6') -split ' ')[0] } catch { $tonerColor = $null } + if ($supplyName -contains 'Fuser' -or $supplyName -contains 'Maint') { + try { $supplyPartNumber = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.6') } catch { $supplyPartNumber = $null } $supplyPartNumber -match '110V-(?.+), ' | Out-Null $supplyPartNumber = $Matches.Name - try { $mainLvl = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.9.1.2') } catch { $mainLvl = $null } - try { $mainMax = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.8.1.2') } catch { $mainMax = $null } + try { $mainLvl = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.9.1.6') } catch { $mainLvl = $null } + try { $mainMax = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.8.1.6') } catch { $mainMax = $null } if ($mainMax -gt 1) { try { $maintKit = $mainLvl / $mainMax } catch { $maintKit = $null } [int]$maintKit = $maintKit * 100 @@ -320,107 +323,99 @@ function Get-SHSPrinter { } } } - - Write-Progress -Activity "Getting hp features from $name" -Completed + else { + try { $supplyName = ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.5') -split ' ')[1] } catch { $tonerColor = $null } + try { $supplyPartNumber = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.5') } catch { $supplyPartNumber = $null } + $supplyPartNumber -match '110V-(?.+), ' | Out-Null + $supplyPartNumber = $Matches.Name + try { $mainLvl = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.9.1.5') } catch { $mainLvl = $null } + try { $mainMax = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.8.1.5') } catch { $mainMax = $null } + if ($mainMax -gt 1) { + try { $maintKit = $mainLvl / $mainMax } catch { $maintKit = $null } + [int]$maintKit = $maintKit * 100 + + if ($null -ne $maintKit) { + $supplies += "| $supplyName" + ":$maintKit%[$supplyPartNumber]" + } + } - } - '^muratec' { - Write-Progress -Activity "Getting muratec features from $name" -Status 'Querying for name' -PercentComplete 30 -ParentId 2 - try { $name = $snmp.Get('.1.3.6.1.4.1.11.2.4.3.5.46.0').toupper() } catch { $name = $null } - Write-Progress -Activity "Getting muratec features from $name" -Status 'Querying for status' -PercentComplete 60 -ParentId 2 - try { $status = $snmp.Get('.1.3.6.1.2.1.43.16.5.1.2.1.1') } catch { $status = $null } - # Start of MAC - Write-Progress -Activity "Getting muratec features from $name" -Status 'Querying for MAC address' -PercentComplete 90 -ParentId 2 - $pMAC = $SNMP.get('.1.3.6.1.4.1.4322.101.1.2.1.5.2.1.1.3.1') - Write-Host $pMAC - $MAC = [System.Text.Encoding]::Default.GetBytes($PMac) | ForEach-Object { - $_.ToString('X2') } - $MAC = $MAC -join ':' - #End of MAC - Write-Progress -Activity "Getting muratec features from $name" -Completed } - default { - + else { + Write-Progress -Activity "Getting hp features from $name" -Status 'Querying for maintenance kit status' -PercentComplete 80 -ParentId 2 + try { $supplyName = ($snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.2') -split ' ')[0] } catch { $supplyName = $null } + try { $supplyPartNumber = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.6.1.2') } catch { $supplyPartNumber = $null } + $supplyPartNumber -match '110V-(?.+), ' | Out-Null + $supplyPartNumber = $Matches.Name + try { $mainLvl = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.9.1.2') } catch { $mainLvl = $null } + try { $mainMax = $snmp.Get('.1.3.6.1.2.1.43.11.1.1.8.1.2') } catch { $mainMax = $null } + if ($mainMax -gt 1) { + try { $maintKit = $mainLvl / $mainMax } catch { $maintKit = $null } + [int]$maintKit = $maintKit * 100 + + if ($null -ne $maintKit) { + $supplies += "| $supplyName" + ":$maintKit%[$supplyPartNumber]" + } + } } - }#end switch -Regex ($model) - #if ($model -like 'SHARP*') {} - - }#end if ($model) - } - else { - $status = "Offline" - $MAC = $CMDB_MAC - $model = $CMDB_model - $serial = $CMDB_serial - $color = "Offline" - $trays = "Offline" - $pagecount = "Offline" - } + + Write-Progress -Activity "Getting hp features from $name" -Completed - $props = [Ordered]@{ - Machine = $printer - Status = $status - IP = "$printerip $ipconfig" - DomainName = $domainName - MAC = $MAC - Model = $model - Serial = $serial - #Comment = $comment - Color = $color - Trays = $trays - #Features = $features - #SystemDescription = $sysdescr0 - #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() - Write-Progress -Activity "Getting printer details for $name" -Completed - return $obj - }#end if ($printerIp) - if ($CMDB_IP) { - $offlineIP = 'CMDB IP - ' + $CMDB_IP - } - else { - $offlineIP = 'No DNS Entry' + } + '^muratec' { + Write-Progress -Activity "Getting muratec features from $name" -Status 'Querying for name' -PercentComplete 30 -ParentId 2 + try { $name = $snmp.Get('.1.3.6.1.4.1.11.2.4.3.5.46.0').toupper() } catch { $name = $null } + Write-Progress -Activity "Getting muratec features from $name" -Status 'Querying for status' -PercentComplete 60 -ParentId 2 + try { $status = $snmp.Get('.1.3.6.1.2.1.43.16.5.1.2.1.1') } catch { $status = $null } + # Start of MAC + Write-Progress -Activity "Getting muratec features from $name" -Status 'Querying for MAC address' -PercentComplete 90 -ParentId 2 + $pMAC = $SNMP.get('.1.3.6.1.4.1.4322.101.1.2.1.5.2.1.1.3.1') + Write-Host $pMAC + $MAC = [System.Text.Encoding]::Default.GetBytes($PMac) | ForEach-Object { + $_.ToString('X2') + } + $MAC = $MAC -join ':' + #End of MAC + Write-Progress -Activity "Getting muratec features from $name" -Completed + } + default { + + } + }#end switch -Regex ($model) + #if ($model -like 'SHARP*') {} + + }#end if ($model) } + $props = [Ordered]@{ Machine = $printer - Status = 'No DNS Entry' - IP = $offlineIP - DomainName = 'No DNS Entry' - MAC = $CMDB_MAC - Model = $CMDB_model - Serial = $CMDB_serial + Status = $status + IP = "$printerip $ipconfig" + DomainName = $domainName + MAC = $MAC + Model = $model + Serial = $serial #Comment = $comment - Color = 'No DNS Entry' - Trays = 'No DNS Entry' - PageCount = 'No DNS Entry' + Color = $color + Trays = $trays + #Features = $features + #SystemDescription = $sysdescr0 + #Addresses = $addr + PageCount = $pagecount + Supplies = $supplies 'CMDB POA' = $CMDB_POA 'CMDB AssetTag' = $CMDB_AssetTag 'CMDB Location' = $CMDB_Location + 'CMDB Status' = $CMDB_Status } $obj = New-Object -TypeName PSObject -Property $props $snmp.close() + Write-Progress -Activity "Getting printer details for $name" -Completed return $obj } -function Get-PrinterIP { - - param ( - [parameter(ValueFromPipeline)] - [string]$printer - ) - - } - function Start-SHSPrinterWeb { param( $printer From bb0255353a8f81cb8b19cf981824fd3fd8e2d957 Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Thu, 13 Feb 2025 15:55:39 -0800 Subject: [PATCH 6/7] Published Jobsprinters --- Get-PC/Public/Get-PC.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Get-PC/Public/Get-PC.ps1 b/Get-PC/Public/Get-PC.ps1 index d2c3380..8ed2b95 100644 --- a/Get-PC/Public/Get-PC.ps1 +++ b/Get-PC/Public/Get-PC.ps1 @@ -72,6 +72,7 @@ Function Get-PC { -GPUpdate | runs a gpupdate -HostnamesByPrinter | grabs all hostnames that have the requested printer installed on it -InstallNet35 | installs .Net 3.5 + -JobsPrinters | optimized version of shsprinter for querying many printers -LogOffUser | remotely logs off user -Monitor | monitors computers for changes in status -NextPrinterName | generates next open printer name From 0cb00c0af6f1fca6c50a01ce50916522b7c87015 Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Thu, 13 Feb 2025 16:02:13 -0800 Subject: [PATCH 7/7] Updated patchnotes --- Get-PC/patchnotes.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Get-PC/patchnotes.txt b/Get-PC/patchnotes.txt index 13cc840..c573a9b 100644 --- a/Get-PC/patchnotes.txt +++ b/Get-PC/patchnotes.txt @@ -1,3 +1,8 @@ +Patch 2025-2-13 +-Add HostnamesByPrinter to list hostnames with printer installed +-Add JobsPrinters to query many printers faster +-Update Apps no longer queries sccm when workstation is online + Patch: 2025-2-4 -Add ADGroups flag to list out a workstation or user's AD groups -Fix Devices reports correct ports for Dell P2425H