by willbs at 2013-03-28 09:05:43
i need to get the ip addresses of a uut, i do this commandby MasterOfTheHat at 2013-03-28 11:14:39
$IPconfig = invoke-command -scriptblock {ipconfig /all} -computername $global:uutName -credential $global:Credential
$IPconfig[18] is
IPv4 Address. . . . . . . . . . . : 192.xxx.x.xxa(Preferred)
$IPconfig[38] is
IPv4 Address. . . . . . . . . . . : 192.xxx.x.xxb(Preferred)
how do i get the ip addresses that are between ": " and "(Preferred)"
i was going to hard code it but the ip length can change
First off, start using .NET objects with PowerShell instead of string manipulation! You can get the IP addresses using the Win32_NetworkAdapterConfiguration WMI class, (lots of other information, too):by willbs at 2013-03-28 11:35:57PS > Get-WMIObject -Class Win32_NetworkAdapterConfiguration -ComputerName . -Filter {IPEnabled = "True"} | Select-Object Description, IPAddress
Description IPAddress
----------- ---------
Broadcom NetXtreme Gigabit Ethernet {10.x.x.29}
VMware Virtual Ethernet Adapter for VMnet1 {192.168.111.1, fe80::b40a:99a6:a50d:c1c}
VMware Virtual Ethernet Adapter for VMnet8 {192.168.227.1, fe80]
Or, if you’re using v3, use the Get-NetworkConnectionInfo cmdlet:PS > Get-NetworkConnectionInfo
Name : Broadcom NetXtreme Gigabit Ethernet
DnsServers : {10.x.x.254, 10.x.x.157, 10.x.x.127}
IPAddresses : {10.x.x.29}
AdapterGuid : c4dd10fe-0bf2-48cb-a7b3-792cd2dbcc6e
MacAddress : E8:39:35:33:EC:30
Identity : c4dd10fe-0bf2-48cb-a7b3-792cd2dbcc6e
IsValid : True
ObjectState : Unchanged
Name : VMware Virtual Ethernet Adapter for VMnet1
DnsServers : {}
IPAddresses : {192.168.111.1, fe80::b40a:99a6:a50d:c1c}
AdapterGuid : ee1d0dbd-7450-4a75-8ab1-9841064303d7
MacAddress : 00:50:56:C0:00:01
Identity : ee1d0dbd-7450-4a75-8ab1-9841064303d7
IsValid : True
ObjectState : Unchanged
Name : VMware Virtual Ethernet Adapter for VMnet8
DnsServers : {}
IPAddresses : {192.168.227.1, fe80::5c71:f473:4ff1:83c5}
AdapterGuid : 1a77e468-d612-4e49-9ccf-489e82a1a54c
MacAddress : 00:50:56:C0:00:08
Identity : 1a77e468-d612-4e49-9ccf-489e82a1a54c
IsValid : True
ObjectState : Unchanged
But if you just really want to use ipconfig, you’ll have to do some fancy string manipulation and get to know regex…
thanks that makes sense but i still need to extract the ip address because i’m getting the info from a remote serverby MasterOfTheHat at 2013-03-28 11:56:14
when i run your command remotely
$IPconfig = invoke-command -scriptblock {Get-WMIObject -Class Win32_NetworkAdapterConfiguration -Filter {IPEnabled = "True"} | Select-Object IPAddress } `
-computername $global:uutName -credential $global:Credential
i get this result
IPAddress PSComputerName RunspaceId
--------- -------------- ----------
{192.168.x.xxx, fe80::5c64:4246:xxx:xxx} stg-xx 4dxxx2-f9xx-xxx-98df-1c4c33xxxx
{192.168.x.xxx, fe80::b88c:87a:xxx:xxx} stg-xx 4dfxxx2-f9xx-xxx-98df-1c4cxxx
$IPconfig.IPAddress will give you the entire array of IP addresses from each computer, ({192.168.x.xxx, fe80::5c64:4246:xxx:xxx}).by willbs at 2013-03-28 12:08:37
You can address each address using the array index: $IPconfig.IPAddress[0] would get you "192.168.x.xxx" and $IPconfig.IPAddress[1] would get you "fe80::5c64:4246:xxx:xxx"
yes it does, coolby MasterOfTheHat at 2013-03-28 12:44:35
sorry about my noobness
thanks guru dude!
No worries! Glad it works. And we were all n00bs once…