Get-Hostname tested and functioning, PCMonitor now uses Output pipeline

This commit is contained in:
Zachary Gorman 2024-07-12 13:50:15 -07:00
parent 0ba1dcee20
commit f5224ff3fc
4 changed files with 54 additions and 83 deletions

View file

@ -3,10 +3,6 @@ function Get-Hostname ($name) {
$res = Get-AssetConversion $name $res = Get-AssetConversion $name
if ($res) { return $res } 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 # 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}$") { if ($name -match "^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$") {
$res = Resolve-DnsName $name $res = Resolve-DnsName $name
@ -14,9 +10,14 @@ function Get-Hostname ($name) {
return $Matches[1] 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 # 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})$") { 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 return $name

View file

@ -27,7 +27,7 @@ function Invoke-PCMonitor {
if ($notify) { if ($notify) {
$null = [System.Windows.MessageBox]::Show($msg) $null = [System.Windows.MessageBox]::Show($msg)
} }
Write-Host "$msg" Write-Output "$msg"
} }
} }
# Update date and time so user knows script hasn't frozen # Update date and time so user knows script hasn't frozen

View file

@ -420,4 +420,13 @@ Function Get-SCCM_USB($ComputerName) {
SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'" SMS_R_System.ResourceId where SMS_R_System.Name = '$ComputerName'"
return Get-WmiObject -namespace $SCCMNAMESPACE -DirectRead -computer $SCCMSERVER -query $usbDevicesQuery 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
} }

View file

@ -178,89 +178,50 @@ Function Get-PC {
continue continue
} }
#Asset Tag Check $oldcomp = $comp
if ($comp.length -eq 5 -and !$SHSPrinter) { $comp = Get-Hostname $comp
$assettag = $comp if (($oldcomp -eq $comp) -and (($comp.length -eq 5 -and !$SHSPrinter) -or ($comp.length -eq 7))) {
$comp = Get-AssetConversion $comp if ($comp.length -eq 5 -and !$SHSPrinter) {
$msg = "$comp Asset Tag not in SMBIOS or CMDB"
if ($null -eq $comp) { Write-Host "`n$msg" -ForegroundColor Red
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
} }
elseif ($comp.length -eq 7) {
#Service Tag Check $msg = "$comp Service Tag not found in SCCM"
} Write-Host "`n$msg" -ForegroundColor Red
elseif ($comp.length -eq 7) {
if (Resolve-DnsName $comp) {
#DREW SUCKS
} }
else {
$serviceTag = $comp
$comp = Get-ServiceTagConversion $comp
if ($null -eq $comp) { $props = [Ordered]@{
Write-Host "`n$serviceTag Service Tag not found in SCCM" -ForegroundColor Red Hostname = "$msg"
Status = ""
$props = [Ordered]@{ 'Current User' = ""
Hostname = "$serviceTag Service Tag not found in SCCM" 'Last User(s)' = ""
Status = "" 'IP | MAC' = ""
'Current User' = "" Model = ""
'Last User(s)' = "" 'OS' = ""
'IP | MAC' = "" 'OS Build' = ""
Model = "" 'BIOS Ver' = ""
'OS' = "" Encryption = ""
'OS Build' = "" 'Free Space' = ""
'BIOS Ver' = "" RAM = ""
Encryption = "" 'SSO Client' = ""
'Free Space' = "" 'Kiosk Role' = ""
RAM = "" 'Citrix Ver' = ""
'SSO Client' = "" 'Asset Tag' = ""
'Kiosk Role' = "" 'Service Tag' = ""
'Citrix Ver' = "" 'Last Reboot' = ""
'Asset Tag' = "" 'TPM Status' = ""
'Service Tag' = "" 'MBAM GPO' = ""
'Last Reboot' = "" Printers = ""
'TPM Status' = ""
'MBAM GPO' = ""
Printers = ""
}
$obj = New-Object -TypeName PSObject -Property $props
$outPutArray += $obj
continue
}
} }
$obj = New-Object -TypeName PSObject -Property $props
$outPutArray += $obj
continue
} }
#DREW SUCKS
#Pulls basic SNMP Data from printer $comp #Pulls basic SNMP Data from printer $comp
if ($SHSPrinter) { if ($SHSPrinter) {
Write-Progress -Activity "Querying Printers" -Status "$comp ($PCID/$NumberofComputers)" -PercentComplete (($PCID / $NumberofComputers) * 100) Write-Progress -Activity "Querying Printers" -Status "$comp ($PCID/$NumberofComputers)" -PercentComplete (($PCID / $NumberofComputers) * 100)