How do I change another computer's network settings from Powershell and/or .NET?

7

How do I change another computer's network settings from Powershell and/or .NET?

Target computers in question are in the same domain as mine and I am an administrator on all machines involved.

Any simple answers?

Andrew J. Brehm

Posted 2010-02-01T15:31:42.297

Reputation: 4 411

1What type of control do You need? What do You mean by remote? Do You only need to change networks settings for script or to trigger script or trigger withs some parameters from remote client? First case should be easy, but for true remote control You need to write/use some server code. For example You can do this using sockets, or use http server. – Maciek Sawicki – 2010-02-01T15:47:57.017

Answers

2

I found the answer.

We can create a WMI object in PowerShell representing the network settings for IP-enabled adapters on a remote server.

$a = Get-WMIObject Win32_NetworkAdapterConfiguration -ComputerName MyServer -Filter IPEnabled=TRUE

This object will most likely be an array of network adapter objects of which only one is needed. So we want to point to that one, probably the first object in the array:

$a = $a[0]

Now we can configure whatever we want, including the IP address.

$a.EnableStatic("192.168.42.2", "255.255.255.0")

The one thing I couldn't figure out is how to determine the netmask!

Andrew J. Brehm

Posted 2010-02-01T15:31:42.297

Reputation: 4 411