Scripting network configuration

I’m working on a project to reconfigure a subnet, and I need to update the network configuration of all the hosts in that subnet. I decided that it’s time to really put PowerShell to work. The Script Center has some good source material, including a PowerShell script to enumerate network configuration and a VB Script to update it. Cross-referencing these with the MSDN details of the Win32_NetworkAdapterConfiguration WMI class, I think I have all the pieces I need.

Here’s a sample:

$computer = "."
$all_nics = get-wmiobject -class "Win32_NetworkAdapterConfiguration" -computer $computer -filter "IPEnabled=TRUE"

foreach ( $nic in $all_nics ) {
write-host "IP Address : " $nic.IPAddress
write-host "MAC Address : " $nic.MACAddress
write-host "Default Gateway : " $nic.DefaultIPGateway
write-host "Subnet Mask : " $nic.IPSubnet

I’ll be working with the EnableStatic and SetGateways methods to make the changes.

Sr. System Administrator at the University of Vermont

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.