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
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

View file

@ -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

View file

@ -421,3 +421,12 @@ Function Get-SCCM_USB($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
}

View file

@ -178,88 +178,49 @@ 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
}
elseif ($comp.length -eq 7) {
$msg = "$comp Service Tag not found in SCCM"
Write-Host "`n$msg" -ForegroundColor Red
}
#Service Tag Check
$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
}
elseif ($comp.length -eq 7) {
if (Resolve-DnsName $comp) {
#DREW SUCKS
}
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
}
}
}
#Pulls basic SNMP Data from printer $comp
if ($SHSPrinter) {