Wednesday, April 25, 2012

Setting custom DNS settings with PowerShell in Server 2012

Okay, the time has come, I can finally say; “Server 2012”
I frequently use custom DNS settings in my lab environments to override the provided DHCP settings and use my own personal domain controllers.
For Server 2008 I used the following commands:
netsh interface ipv4 add dnsserver "local area connection" x.x.x.x 1
netsh interface ipv4 add dnsserver "local area connection" x.x.x.x 2
For the Windows 8 Preview I simply adapted this:
netsh interface ipv4 add dnsserver "Wired Ethernet Connection" x.x.x.x 1
netsh interface ipv4 add dnsserver "Wired Ethernet Connection" x.x.x.x 2
*Note the change to the interface name
Being an embracer of PowerShell and all the 2000+ new cmdlets in Windows Server I decided to figure out how to do this the PowerShell way.
Well, I have to say it took a while just to find the right cmdlets because I began at IPAddress or IPAdapter.  Not thinking that there would be a DnsClientServerAddress.
Now, to set, just turn this around to the Set-
Set-DnsClientServerAddress -InterfaceAlias vEthernet* -ServerAddresses "x.x.x.x","x.x.x.x"
Note how I feed in the multiple addresses, as list of individual comma separated strings.

Then, there is the one-liner (I discuss finding the proper NetAdapter is other posts).

Get-NetAdapter | Set-DnsClientServerAddress -ServerAddresses "x.x.x.x","x.x.x.x"

Monday, April 16, 2012

Windows 8 in a VM on 2008 R2 Hyper-V

Update:  As of October 9, 2012, the update has been superseded by 2744129. Go to to find that update, where it states the supersedence in the documentation.

This is an interesting patch that someone recently pointed me to:
Apply this patch to your Server 2008 R2 Hyper-V Server so that you can install Windows 8 in a VM.
If you do not apply this patch and you attempt to run Windows 8 within a VM: note the symptoms in the KB article:
  • The Windows Developer Preview or Windows Server Developer Preview virtual machine stops responding.
  • The Windows Server 2008 R2 host computer displays a stop error message and restarts automatically. This behavior brings down all other running virtual machines together with the host computer.
That does not sound good.
So, if you have a Hyper-V server that suddenly crashes and reboots, and you know that someone has downloaded the Windows 8 beta and might be installing it into a VM…  Well, you suddenly have an idea what might be going on.

Tuesday, April 10, 2012

PowerShell is about doing things not writing scripts

With PowerShell finally going cross-platform with Windows 8 I keep hearing the same comments over and over – “just write a script for that”

You know what?  Not everything needs a script.  A few commands maybe, but not a script.

Why do I bring this up?  Because script writing is intimidating.  You have to understand loops, arrays, object types, schemas, properties, and other developer-type things.

But if you only have a make a couple modifications to settings, every so often or discover something.  You don’t need a script for that, you need some commands.

And this is where the lingo and the action are becoming disconnected. 

If you look at it one way, PowerShell is to Windows what BASH is to Linux and what Command was to DOS.  A way to get things done.  A place to find things and do things.

Did everything that you did in DOS have to turn into a BATCH script?  No.  But back in the day we did write some pretty complex user logon and logoff scripts.  Why?

Because certain tasks needed to be repeated over and over.  That is where we need a script over a few captured commands.

My other big gripe is script or command examples.  Folks that blog some long and highly complex one-liner that is very difficult to comprehend because you get lost in the pipeline.  The big disservice being that they never do it long hand.

Most folks that I encounter these days are either at the 100 level of using PowerShell or at the 300 – 400 level.  You just straight through the 200 level when you write a script or suddenly grok objects.