Set Static IP Address via Powershell


I am trying to get a script together that will configure a static IP address, DNS, and WINS server settings. The instructions here are great, except the DNS part doesn't work.

Here are the commands in the script:

$wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'"

$wmi.EnableStatic("", "")

$wmi.SetGateways("", 1)

$wmi.SetDNSServerSearchOrder("", "", "")


Each time I run the script it fails on the DNS portion. I am doing this on Windows Server 2012. The specific error message is: Cannot find an overload for "SetDNSServerSearchOrder" and the argument count: "3".

Any ideas? Thanks
LVL 27
Jason WatkinsIT Project LeaderAsked:
Who is Participating?
Raheman M. AbdulConnect With a Mentor Senior Infrastructure Support Analyst & Systems DeveloperCommented:
make it as array:
$wmi.SetDNSServerSearchOrder(@("", "", ""))

Open in new window

or save the DNS settings into a variable which makes it an array variable like this:
$dnsSearchOrder = "", "", ""
$wmi.SetDNSServerSearchOrder($dnsSearchOrder )

Open in new window

Jason WatkinsIT Project LeaderAuthor Commented:
Option 1 worked great! (after I ran the script as an admin)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.