Solved

Set Static IP Address via Powershell

Posted on 2014-12-16
2
393 Views
Last Modified: 2014-12-16
Hi,

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.

http://blogs.technet.com/b/heyscriptingguy/archive/2012/02/28/use-powershell-to-configure-static-ip-and-dns-settings.aspx

Here are the commands in the script:

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

$wmi.EnableStatic("192.168.1.2", "255.255.255.0")

$wmi.SetGateways("192.168.1.1", 1)

$wmi.SetDNSServerSearchOrder("208.67.220.220", "208.67.222.222", "8.8.8.8")

$wmi.SetWINSServer("192,168,1,1")

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
0
Comment
Question by:Jason Watkins
2 Comments
 
LVL 18

Accepted Solution

by:
Raheman M. Abdul earned 500 total points
ID: 40502566
make it as array:
 
$wmi.SetDNSServerSearchOrder(@("208.67.220.220", "208.67.222.222", "8.8.8.8"))

Open in new window


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

Open in new window

0
 
LVL 27

Author Comment

by:Jason Watkins
ID: 40502644
Option 1 worked great! (after I ran the script as an admin)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

What to do when Windows Update is not working correctly? What tools can I use to detect the cause of the malfunction problem? What does this numeric error code mean? These and other questions that you have been asking in the past are answered here (…
Synchronize a new Active Directory domain with an existing Office 365 tenant
In this Micro Tutorial viewers will learn how to restore their server from Bare Metal Backup image created with Windows Server Backup feature. As an example Windows 2012R2 is used.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now