Updated hostname resolution
This commit is contained in:
parent
f950cd11a7
commit
ee682348fe
|
|
@ -7,7 +7,7 @@ function Get-Hostname ([string]$name) {
|
||||||
$cmdbData = Search-ISMBO -bo cis -filter "AssetTag eq '$name'" -RawFilter
|
$cmdbData = Search-ISMBO -bo cis -filter "AssetTag eq '$name'" -RawFilter
|
||||||
} catch { $cmdbData = $null }
|
} catch { $cmdbData = $null }
|
||||||
if ( $cmdbData ) { return $cmdbData.Name, '' }
|
if ( $cmdbData ) { return $cmdbData.Name, '' }
|
||||||
else { $errMsg += "$name Asset Tag not in SMBIOS or CMDB. " }
|
else { $errMsg += "$name Asset Tag not in SMBIOS nor CMDB`n" }
|
||||||
}
|
}
|
||||||
# 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}$") {
|
||||||
|
|
@ -15,7 +15,7 @@ function Get-Hostname ([string]$name) {
|
||||||
if ($res -and $res.NameHost -and ($res.NameHost -match "([^.]*)\.int\.samhealth\.net")) {
|
if ($res -and $res.NameHost -and ($res.NameHost -match "([^.]*)\.int\.samhealth\.net")) {
|
||||||
return $Matches[0],''
|
return $Matches[0],''
|
||||||
} else {
|
} else {
|
||||||
$errMsg += "$name IP Address couldn't be resolved to hostname"
|
$errMsg += "$name IP Address couldn't be resolved to hostname`n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($name.Length -eq 7) {
|
if ($name.Length -eq 7) {
|
||||||
|
|
@ -25,20 +25,27 @@ function Get-Hostname ([string]$name) {
|
||||||
$cmdbData = Search-ISMBO -bo cis -filter "SerialNumber eq '$name'" -RawFilter
|
$cmdbData = Search-ISMBO -bo cis -filter "SerialNumber eq '$name'" -RawFilter
|
||||||
} catch { $cmdbData = $null }
|
} catch { $cmdbData = $null }
|
||||||
if ( $cmdbData ) { return $cmdbData.Name, '' }
|
if ( $cmdbData ) { return $cmdbData.Name, '' }
|
||||||
else { $errMsg += "$name Service Tag not found in SCCM"}
|
else { $errMsg += "$name Service Tag not found in SCCM nor CMDB`n"}
|
||||||
}
|
}
|
||||||
# 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
|
$res = Get-SCCM_PCFromMAC $name
|
||||||
if ($res) { return $res,'' }
|
if ($res) { return $res,'' }
|
||||||
else { $errMsg += "$name MAC Address not found in SCCM"}
|
else { $errMsg += "$name MAC Address not found in SCCM`n"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Last resort checks
|
||||||
|
$sccmMatches = Get-SCCM_HostnameMatch $name
|
||||||
|
if ($SCCMMatches -and $SCCMMatches.Count -lt 2) {
|
||||||
|
return $SCCMMatches.Name,''
|
||||||
|
} elseif (!$SCCMMatches) { $errMsg += "No SCCM match found`n" }
|
||||||
|
elseif ($SCCMMatches.Count -ge 2) { $errMsg += "Many SCCM matches found`n" }
|
||||||
|
|
||||||
$cmdbMatches = Find-ISMBO -bo cis -SearchQuery $name
|
$cmdbMatches = Find-ISMBO -bo cis -SearchQuery $name
|
||||||
if ($cmdbMatches -and $cmdbMatches.Count -lt 2) {
|
if ($cmdbMatches -and $cmdbMatches.Count -lt 2) {
|
||||||
return $cmdbMatches.Name,''
|
return $cmdbMatches.Name,''
|
||||||
} elseif (!$cmdbMatches) { $errMsg += "No CMDB match found" }
|
} elseif (!$cmdbMatches) { $errMsg += "No CMDB match found`n" }
|
||||||
elseif ($cmdbMatches.Count -ge 2) { $errMsg += "Many CMDB matches found" }
|
elseif ($cmdbMatches.Count -ge 2) { $errMsg += "Many CMDB matches found`n" }
|
||||||
|
|
||||||
return $name, $errMsg
|
return $name, $errMsg
|
||||||
}
|
}
|
||||||
|
|
@ -505,3 +505,9 @@ Function Get-SCCM_UserLastLoggedOn($user) {
|
||||||
$computerSCCM = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMUserQuery | Select-Object -ExpandProperty Name
|
$computerSCCM = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMUserQuery | Select-Object -ExpandProperty Name
|
||||||
return $computerSCCM
|
return $computerSCCM
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Function Get-SCCM_HostnameMatch($name) {
|
||||||
|
$SCCMQuery = "select distinct SMS_R_System.Name from SMS_R_System where SMS_R_System.Name is like '%$name%'"
|
||||||
|
$res = Get-WmiObject -namespace $SCCMNameSpace -DirectRead -computer $SCCMServer -query $SCCMQuery | Select-Object -ExpandProperty Name
|
||||||
|
return $res
|
||||||
|
}
|
||||||
|
|
@ -193,7 +193,7 @@ Function Get-PC {
|
||||||
|
|
||||||
|
|
||||||
$searchResults = Search-CMDB -Location $searchInput | Sort-Object -Property Hostname
|
$searchResults = Search-CMDB -Location $searchInput | Sort-Object -Property Hostname
|
||||||
if($searchResults -eq $null){
|
if($null -eq $searchResults){
|
||||||
Write-Host 'No results for given search' -ForegroundColor Yellow
|
Write-Host 'No results for given search' -ForegroundColor Yellow
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
Patch:
|
||||||
|
-Fix Hostnames now check SCCM for a name match as a fallback
|
||||||
|
|
||||||
Patch: 2024-09-05
|
Patch: 2024-09-05
|
||||||
-Fix Spark! hangs sometimes, added timeout in BatchInvokes
|
-Fix Spark! hangs sometimes, added timeout in BatchInvokes
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue