Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell: Getting IP v4 Address on a multihomed system

$
0
0

Hello,
I started setting up a Powershell script as Shutdown script for the clients in the domain. It's last task is writing some inventory information into a file on a shared folder, which it does. The problem: I need to take note of the IP v4 IP addresses and export this information into a csv file. Current syntax to get the related data:

$ip = get-wmiobject win32_networkadapterconfiguration -filter "ipenabled=true"
$ip = $ip.ipaddress[0]

works well for most machines here, but a few are running wired and wireless connection at the same time.
Here the attempt addressing $ip.ipaddress[0] results in error "Cannot index into a null array." (Validated this by having a user disabling WLAN adapter and rerunning the script - no error any more.)

The result in the log (since $ErrorActionPreference = 'SilentlyContinue' is set) looked pretty strange for the field IP address: \\PCNAME\root\cimv2:Win32_NetworkAdapterConfiguration.Index=7 \\PCNAME\root\cimv2:Win32_NetworkAdapterConfiguration.Index=11

Now I hit a brain lock, so any help is welcome. The ideal scenario would be, that the script delivers the IP v4 addresses of each network adapter as a complete comma separatedstring (since the database, which needs to consume this value at a later step, has only one field for this property, i.e. 192.168.1.100,192.168.1.50).

Best greetings from Germany
Olaf


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>