2024-07-15 15:54:31 +00:00
|
|
|
function Get-Hostname ([string]$name) {
|
2024-07-24 22:37:27 +00:00
|
|
|
$errMsg = ''
|
2024-07-11 18:33:30 +00:00
|
|
|
if ($name.Length -eq 5) {
|
|
|
|
|
$res = Get-AssetConversion $name
|
2024-07-24 22:37:27 +00:00
|
|
|
if ($res) { return $res,'' }
|
2024-08-07 18:33:25 +00:00
|
|
|
try {
|
|
|
|
|
$cmdbData = Search-ISMBO -bo cis -filter "AssetTag eq '$name'" -RawFilter
|
|
|
|
|
} catch { $cmdbData = $null }
|
2024-08-13 21:19:17 +00:00
|
|
|
if ( $cmdbData ) { return $cmdbData.Name, '' }
|
2024-08-07 18:33:25 +00:00
|
|
|
else { $errMsg += "$name Asset Tag not in SMBIOS or CMDB. " }
|
2024-07-11 18:33:30 +00:00
|
|
|
}
|
|
|
|
|
# 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
|
|
|
|
|
if ($res -and $res.NameHost -and ($res.NameHost -match "([^.]*)\.int\.samhealth\.net")) {
|
2024-08-29 16:44:47 +00:00
|
|
|
return $Matches[0],''
|
2024-07-24 22:37:27 +00:00
|
|
|
} else {
|
|
|
|
|
$errMsg += "$name IP Address couldn't be resolved to hostname"
|
2024-07-11 18:33:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
2024-07-12 20:50:15 +00:00
|
|
|
if ($name.Length -eq 7) {
|
|
|
|
|
$res = Get-ServiceTagConversion $name
|
2024-07-24 22:37:27 +00:00
|
|
|
if ($res) { return $res,'' }
|
2024-08-13 21:19:17 +00:00
|
|
|
try {
|
|
|
|
|
$cmdbData = Search-ISMBO -bo cis -filter "SerialNumber eq '$name'" -RawFilter
|
|
|
|
|
} catch { $cmdbData = $null }
|
|
|
|
|
if ( $cmdbData ) { return $cmdbData.Name, '' }
|
2024-07-24 22:37:27 +00:00
|
|
|
else { $errMsg += "$name Service Tag not found in SCCM"}
|
2024-07-12 20:50:15 +00:00
|
|
|
}
|
2024-07-11 18:33:30 +00:00
|
|
|
# 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})$") {
|
2024-07-12 20:50:15 +00:00
|
|
|
$res = Get-SCCM_PCFromMAC $name
|
2024-07-24 22:37:27 +00:00
|
|
|
if ($res) { return $res,'' }
|
|
|
|
|
else { $errMsg += "$name MAC Address not found in SCCM"}
|
2024-07-11 18:33:30 +00:00
|
|
|
}
|
2024-08-29 16:44:47 +00:00
|
|
|
|
|
|
|
|
$cmdbMatches = Find-ISMBO -bo cis -SearchQuery $name
|
|
|
|
|
if ($cmdbMatches -and $cmdbMatches.Count -lt 2) {
|
|
|
|
|
return $cmdbMatches.Name,''
|
2024-09-04 22:55:01 +00:00
|
|
|
} elseif (!$cmdbMatches) { $errMsg += "No CMDB match found" }
|
|
|
|
|
elseif ($cmdbMatches.Count -ge 2) { $errMsg += "Many CMDB matches found" }
|
2024-08-29 16:44:47 +00:00
|
|
|
|
2024-07-24 22:37:27 +00:00
|
|
|
return $name, $errMsg
|
2024-07-11 18:33:30 +00:00
|
|
|
}
|