diff --git a/Private/Get-Hostname.ps1 b/Private/Get-Hostname.ps1 index 6e8f215..9955d68 100644 --- a/Private/Get-Hostname.ps1 +++ b/Private/Get-Hostname.ps1 @@ -3,10 +3,6 @@ function Get-Hostname ($name) { $res = Get-AssetConversion $name if ($res) { return $res } } - if ($name.Length -eq 7) { - $res = Get-ServiceTagConversion $name - if ($res) { return $res } - } # 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 @@ -14,9 +10,14 @@ function Get-Hostname ($name) { return $Matches[1] } } + if ($name.Length -eq 7) { + $res = Get-ServiceTagConversion $name + if ($res) { return $res } + } # Regex to match MAC Address brought to you by https://stackoverflow.com/a/4260512 if ($name -match "^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$") { - + $res = Get-SCCM_PCFromMAC $name + if ($res) { return $res } } return $name diff --git a/Private/PCMonitor.ps1 b/Private/PCMonitor.ps1 index d16adf2..609db55 100644 --- a/Private/PCMonitor.ps1 +++ b/Private/PCMonitor.ps1 @@ -27,7 +27,7 @@ function Invoke-PCMonitor { if ($notify) { $null = [System.Windows.MessageBox]::Show($msg) } - Write-Host "$msg" + Write-Output "$msg" } } # Update date and time so user knows script hasn't frozen diff --git a/Private/SCCMQuery.ps1 b/Private/SCCMQuery.ps1 index b7a058e..fef6f1b 100644 --- a/Private/SCCMQuery.ps1 +++ b/Private/SCCMQuery.ps1 @@ -420,4 +420,13 @@ Function Get-SCCM_USB($ComputerName) { SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'" return Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $usbDevicesQuery +} + +function Get-SCCM_PCFromMAC($mac) { + # Try to get address in the right format first like 12:34:56:78:9A:BC + # Covers deliminating '-', '.', or no delimeter + $mac = $mac -replace '([^:.-]{2})[-.]?[^:](?!$)', '$1:' + $pcFromMacQuery = "select SMS_R_System.Name from SMS_R_System where SMS_R_System.MACAddresses = '$mac'" + + return (Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $pcFromMacQuery).Name } \ No newline at end of file diff --git a/Public/Get-PC.ps1 b/Public/Get-PC.ps1 index c6778ab..c2aa1ff 100644 --- a/Public/Get-PC.ps1 +++ b/Public/Get-PC.ps1 @@ -178,89 +178,50 @@ Function Get-PC { continue } - #Asset Tag Check - if ($comp.length -eq 5 -and !$SHSPrinter) { - $assettag = $comp - $comp = Get-AssetConversion $comp - - if ($null -eq $comp) { - Write-Host "`n$assettag Asset Tag not in SMBIOS or CMDB" -ForegroundColor Red - - $props = [Ordered]@{ - Hostname = "$assettag Asset Tag not in SMBIOS" - Status = "" - 'Current User' = "" - 'Last User(s)' = "" - 'IP | MAC' = "" - Model = "" - 'OS' = "" - 'OS Build' = "" - 'BIOS Ver' = "" - Encryption = "" - 'Free Space' = "" - RAM = "" - 'SSO Client' = "" - 'Kiosk Role' = "" - 'Citrix Ver' = "" - 'Asset Tag' = "" - 'Service Tag' = "" - 'Last Reboot' = "" - 'TPM Status' = "" - 'MBAM GPO' = "" - Printers = "" - } - $obj = New-Object -TypeName PSObject -Property $props - - $outPutArray += $obj - - continue + $oldcomp = $comp + $comp = Get-Hostname $comp + if (($oldcomp -eq $comp) -and (($comp.length -eq 5 -and !$SHSPrinter) -or ($comp.length -eq 7))) { + if ($comp.length -eq 5 -and !$SHSPrinter) { + $msg = "$comp Asset Tag not in SMBIOS or CMDB" + Write-Host "`n$msg" -ForegroundColor Red } - - #Service Tag Check - } - elseif ($comp.length -eq 7) { - if (Resolve-DnsName $comp) { - #DREW SUCKS + elseif ($comp.length -eq 7) { + $msg = "$comp Service Tag not found in SCCM" + Write-Host "`n$msg" -ForegroundColor Red } - else { - $serviceTag = $comp - $comp = Get-ServiceTagConversion $comp - if ($null -eq $comp) { - Write-Host "`n$serviceTag Service Tag not found in SCCM" -ForegroundColor Red - - $props = [Ordered]@{ - Hostname = "$serviceTag Service Tag not found in SCCM" - Status = "" - 'Current User' = "" - 'Last User(s)' = "" - 'IP | MAC' = "" - Model = "" - 'OS' = "" - 'OS Build' = "" - 'BIOS Ver' = "" - Encryption = "" - 'Free Space' = "" - RAM = "" - 'SSO Client' = "" - 'Kiosk Role' = "" - 'Citrix Ver' = "" - 'Asset Tag' = "" - 'Service Tag' = "" - 'Last Reboot' = "" - 'TPM Status' = "" - 'MBAM GPO' = "" - Printers = "" - } - $obj = New-Object -TypeName PSObject -Property $props - - $outPutArray += $obj - - continue - } + $props = [Ordered]@{ + Hostname = "$msg" + Status = "" + 'Current User' = "" + 'Last User(s)' = "" + 'IP | MAC' = "" + Model = "" + 'OS' = "" + 'OS Build' = "" + 'BIOS Ver' = "" + Encryption = "" + 'Free Space' = "" + RAM = "" + 'SSO Client' = "" + 'Kiosk Role' = "" + 'Citrix Ver' = "" + 'Asset Tag' = "" + 'Service Tag' = "" + 'Last Reboot' = "" + 'TPM Status' = "" + 'MBAM GPO' = "" + Printers = "" } + $obj = New-Object -TypeName PSObject -Property $props + + $outPutArray += $obj + + continue } + #DREW SUCKS + #Pulls basic SNMP Data from printer $comp if ($SHSPrinter) { Write-Progress -Activity "Querying Printers" -Status "$comp ($PCID/$NumberofComputers)" -PercentComplete (($PCID / $NumberofComputers) * 100)