ok,
Here is the best part you'll need:
$rs = [System.Net.Dns]::GetHostAddresses($i)|select-object IPAddressToString -expandproperty IPAddressToString
now, I wrote this and tested it using powershell v2 ctp3, and it should work on the Lower versions but have not tested it.
with that line, you will have just an IP address in the var, $rs. from there you can do other things and fancy stuff, all aglore.
the select statement cleans up the output of: [System.Net.Dns]::GetHostAddresses($i) otherwise the output is not really useable as the output is formated in its own colums, with outher propertys. the select-object strips everything out except the IP address.
-Nex6
5 comments:
Thank you for posting this. I had spent quite some time googling for how to do exactly this, stripping all the nonsense and just leaving the bare address.
THANKS! I was banging my head against the wall trying to extract/isolate JUST the IP.
Regards,
Tyson
I am always searching for quality posts and articles and this is what I found here, I hope you will be adding more in future. Thanks
my car electronics
extraordinary gadgets
Hey thanks a lot for this. I keep forgetting how to extract object properties. Also I was trying to do it with System.Net.Dns GetHostByName which was not as successful.
I wanted to take the data to a file. When I do that I get this error :
At line:3 char:35
+ [System.Net.Dns]::GetHostAddresses <<<< ($i)|select-object IPAddressToString
-expandproperty IPAddressToString >> Output.txt
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Post a Comment