VMware Cloud Community
drivera01
Enthusiast
Enthusiast
Jump to solution

pull info from a nslookup and populate a variable?

So if I have

PowerCLI P:\My Documents> nslookup mickeymouse
Server:  lookup.mycompany.com
Address:  192.56.45.90

Name:    mickeymouse.mycompany.com
Address:  192.30.2.4

So with the above information, is it even possible to query a nslookup and populate the IP into a variable.

$ip

So what I am wanting  is to just to have to input the hostname of the vm I intend to create and have it query  to pull its address. Is it possible, is there something better than nslookup?

I know of how to get it this way but I do not know how to just pull the exact IP and not the other parts of the string....

PowerCLI P:\My Documents $test =  [System.Net.Dns]::GetHostAddresses("vmname01") |select IPADDRESSToString
PowerCLI P:\My Documents\ Write-Host $test
@{IPAddressToString=192.30.2.4}

I need just in my variable...

192.30.2.4

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

[System.Net.Dns]::GetHostAddresses("vmname01") | Select -ExpandProperty IPAddressToString 

You can also use the output from ipconfig, that will require a RegEx mask


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

[System.Net.Dns]::GetHostAddresses("vmname01") | Select -ExpandProperty IPAddressToString 

You can also use the output from ipconfig, that will require a RegEx mask


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
drivera01
Enthusiast
Enthusiast
Jump to solution

i was tttthhhaaattt close...

Thank you LucD!!!!

Reply
0 Kudos