From 0ba1dcee2072f76f3b7ba7331279bd6fd9eaa1bc Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Thu, 11 Jul 2024 11:33:30 -0700 Subject: [PATCH] Started on Get-Hostname --- Private/Get-Hostname.ps1 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Private/Get-Hostname.ps1 diff --git a/Private/Get-Hostname.ps1 b/Private/Get-Hostname.ps1 new file mode 100644 index 0000000..6e8f215 --- /dev/null +++ b/Private/Get-Hostname.ps1 @@ -0,0 +1,23 @@ +function Get-Hostname ($name) { + if ($name.Length -eq 5) { + $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 + if ($res -and $res.NameHost -and ($res.NameHost -match "([^.]*)\.int\.samhealth\.net")) { + return $Matches[1] + } + } + # 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})$") { + + } + + return $name +} \ No newline at end of file