Created
May 17, 2016 20:43
-
-
Save Graham-Beer/731975067e2a7f505b440b2ba934c1c2 to your computer and use it in GitHub Desktop.
Get IP from Host / Host from IP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Details | |
Small function to find either IP address from Host or Host from IP | |
By G Beer | |
#> | |
Function Get-NetDetails { | |
[CmdletBinding(DefaultParameterSetName='ByIP')] | |
param ( | |
[Parameter(Mandatory = $true, ParameterSetName = 'ByIP')] | |
[System.String] | |
$IP, | |
[Parameter(Mandatory = $true, ParameterSetName = 'ByHost')] | |
[System.String] | |
$HostName | |
) | |
switch ($PsCmdlet.ParameterSetName){ | |
'ByIP' { Try {"HostName is: " + [system.net.dns]::GetHostByAddress($IP).hostname} Catch [exception] { $_ } } | |
'ByHost' { Try {"IP Address is: " + ([system.net.dns]::GetHostByName($HostName).AddressList).IPAddressToString} Catch [exception] { $_ } } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment