Configuring Static IP and DNS Addresses with Windows PowerShell

Let’s dive into using Windows PowerShell to set static IP and DNS addresses on a server. In this walkthrough, I’ll walk you through the process with a concise breakdown of the steps.

Here’s the script, named `SetStaticIP.ps1`, that performs the IP and DNS configuration:

$wmi = Get-WmiObject win32_networkadapterconfiguration -filter “ipenabled = ‘true'”
$wmi.EnableStatic(“”, “”)
$wmi.SetGateways(“”, 1)

Even when dealing with script execution policy restrictions, Windows PowerShell ISE comes to the rescue. You can run the commands interactively within ISE, bypassing those policy limitations.

Breaking down the commands:

  1. $wmi = Get-WmiObject…: Retrieve network adapter configurations for adapters enabled for IP using the `Get-WmiObject` cmdlet and the `Win32_NetworkAdapterConfiguration` WMI class.
  2. $wmi.EnableStatic(…): Use the `EnableStatic` method to set the IP address and subnet mask.
  3. $wmi.SetGateways(…): Utilize `SetGateways` to specify gateway IP and metric.
  4. $wmi.SetDNSServerSearchOrder(…): Set the DNS server order using `SetDNSServerSearchOrder`.

Upon executing the commands, validate the IP change through GUI tools. These commands are efficient for resolving issues like race conditions, providing stability to your server environment.

In essence, Windows PowerShell showcases its flexibility and command-line prowess, even when dealing with policy constraints. It’s an invaluable tool for efficient IT management tasks, whether it’s IP configuration or tackling complex server challenges.

Leave a comment

Your email address will not be published. Required fields are marked *

1 × five =