Richard Siddaway's Blog

Archive for the ‘Windows 2012 R2’ Category

Creating DNS records

without comments

Following on from my previous post about creating a reverse lookup zone in DNS here’s a function to create records in that zone.


The function takes an IP address and name (of host) and uses Add-DnsServerResourceRecordA  to add the record to the forward lookup zone – I use my default AD zone.


The function then splits the IP address. Uses the last octet for the name in the reverse record. Creates the reverse lookup zone from the first 3 octets – notice how the range parameter is used in a decreasing way to specify the order of the octets – to create the reverse lookup zone. The host name and zone are used to create the FQDN of the host.


Add-DnsServerResourceRecordPtr  is used to create the reverse (PTR) record.


function new-dnsrecord {
  param (
    [string]$zone = ‘’

  Add-DnsServerResourceRecordA -Name $name -ZoneName $zone -AllowUpdateAny -IPv4Address $ipaddress

  $octs = $ipaddress -split ‘\.’

  $revname = "$($octs[3])"
  $revzone = "$($octs[2..0] -join ‘.’)"
  $fqdn = "$name.$zone"
  Add-DnsServerResourceRecordPtr -Name $revname -ZoneName $revzone -AllowUpdateAny -PtrDomainName $fqdn


Written by richardsiddaway

October 30th, 2015 at 5:39 pm

Creating a DHCP reservation

without comments

For my demo at the PowerShell Summit I wanted to use DHCP for the Linux machine but guarantee that it had a specific IP address.  Time to create a DHCP reservation


The DHCP module in Windows Server 2012 and 2012 R2 enables you to create a reservation:

Add-DhcpServerv4Reservation -ScopeId -IPAddress -ClientId 00155D36C906 -Description "LInux machine" -Name "SphinxLX01"


The clientid is the VMs MAC address.


You can view the current reservations:


£> Get-DhcpServerv4Reservation -ScopeId | fl *

IPAddress             :
ScopeId               :
AddressState          : ActiveReservation
ClientId              : 00-15-5d-36-c9-06
Description           : LInux machine
Name                  : SphinxLX01
Type                  : Both


You can view current leases:

£> Get-DhcpServerv4Lease -ScopeId | fl *

IPAddress             :
ScopeId               :
AddressState          : ActiveReservation
ClientId              : 00-15-5d-36-c9-06
ClientType            : Dhcp
Description           : LInux machine
DnsRegistration       : NotApplicable
DnsRR                 : NoRegistration
HostName              : SphinxLX01
LeaseExpiryTime       :
NapCapable            : False
NapStatus             : FullAccess
PolicyName            :
ProbationEnds         :
ServerIP              :


And all from the comfort of your very own PowerShell prompt

Written by richardsiddaway

September 20th, 2014 at 4:08 pm

Authorising a DHCP server and creating a scope

without comments

I recently re-built my test lab and now need to authorise the DHCP server.

You can test the DHCP server:

£> Get-DhcpServerSetting

IsDomainJoined            : True
IsAuthorized              : False
DynamicBootp              : True
RestoreStatus             : False
ConflictDetectionAttempts : 0
NpsUnreachableAction      : Full
NapEnabled                : False
ActivatePolicies          : True

Authorisation is straightforward

Add-DhcpServerInDC -DnsName -IPAddress

If you only have a single NIC in your DHCP server you don’t need to worry about the IP address

£> Get-DhcpServerSetting

IsDomainJoined            : True
IsAuthorized              : True
DynamicBootp              : True
RestoreStatus             : False
ConflictDetectionAttempts : 0
NpsUnreachableAction      : Full
NapEnabled                : False
ActivatePolicies          : True

Create a scope and activate it

Add-DhcpServerv4Scope -ComputerName server02 -Name "Manticore Scope"  -StartRange -EndRange -Description "Scope for Manticore domain" -Type DHCP -State Active -SubnetMask -LeaseDuration (New-TimeSpan -Days 2)

ComputerName is the name of the DHCP server otherwise the parameters are self explanatory

To view all scopes

Get-DhcpServerv4Scope -ComputerName server02

To view specific scope

Get-DhcpServerv4Scope -ComputerName server02 -ScopeId | fl

ScopeId          :
Name             : Manticore Scope
Description      : Scope for Manticore domain
SuperscopeName   :
SubnetMask       :
StartRange       :
EndRange         :
LeaseDuration    : 2.00:00:00
NapProfile       :
NapEnable        : False
Delay(ms)        : 0
State            : Active
Type             : Dhcp
MaxBootpClients  : 4294967295
ActivatePolicies : True

Written by richardsiddaway

September 7th, 2014 at 11:40 am

Patching Server Core

without comments

I’ve been rebuilding my test lab after installing a SSD into the machine running it in place of the SATA drive.  Huge improvement in load speed of virtual machines – well worth the cost.

I usually have a number of server core machines in the lab and use WSUS for patching.  One issue I’d never really resolved was patching those server core machines  – the control panel fro Windows Update isn’t available!

Finally found a solution in the Windows Update PowerShell module from

Install the module and then you can install your patches using

Get-WUInstall –AcceptAll

I’m running Windows 2012 R2 on all my servers so the modules auto load

Written by richardsiddaway

August 28th, 2014 at 6:54 pm

Installing Centos in Windows 2012 R2 Hyper-V

without comments

I need to create a virtual machine with CentOS 6.5 as the guest OS.


I clicked through creating the VM and discovered that the install wouldn’t work. Eventually tracked down the issues.


Keep the following points in mind as you create your VM:

  1. Create the VM as a generation 1 virtual machine
  2. Ensure the virtual disk controller and disk are IDE
  3. Ensure a legacy network adapter is used – may need to create the VM without a network adapter and add the adapter before the install
  4. If asked to test the install media (iso image) be aware that it will be ejected after the test so you’ll need to open it again
  5. keep it simple and only have 1 network adapter
  6. Use the map to find the nearest city to get the time zone – scrolling though the list is boring

Written by richardsiddaway

August 10th, 2014 at 12:03 pm

Formatting disks – – the new way

without comments

Last time I showed how to format disks using the Win32_Volume CIM class. If you need to perform this activity on a Windows Server 2012/Windows 8 or later system you can use a couple of cmdlets from the Storage module

Get-Volume | where DriveLetter -ne ‘C’ | Format-Volume -FileSystem NTFS -Confirm:$false –WhatIf


If you’ve not looked at the Storage module before there is a lot of useful cmdlets.

Written by richardsiddaway

July 14th, 2014 at 12:38 pm

Working with Server Core–renaming the machine

without comments

When you create a new Windows server it usually assigns a name of its own. I always prefer using my own names for servers – I usually create the name so it gives some indication of the machine’s purpose.

Renaming a computer is simple

On the local computer run

Rename-Computer -NewName test01 -Force –Restart

This will rename the computer and force the restart.

If you want to do this remotely the cmdlet has a –ComputerName parameter plus the ability to define local or domain credentials.

Written by richardsiddaway

May 13th, 2014 at 1:56 pm

Working with Server Core–setting IP addresses

without comments

When you create a new Windows machine it defaults to using DHCP to get an IP address. While that is fine for client machines most people apply a static address to their servers. Up until Windows 2012 you had 2 choices – use the GUI or use PowerShell and WMI.

Server 2012 introduced a host of cmdlets for administering your network settings.  Setting an IP address is simple as this:

New-NetIPAddress -InterfaceIndex 12 -IPAddress ‘’ -AddressFamily IPv4 -PrefixLength 24


I haven’t used it but you can also set the default gateway which would make the command

New-NetIPAddress -InterfaceIndex 12 -IPAddress ‘’ -AddressFamily IPv4 -PrefixLength 24 -DefaultGateway ‘’


The DNS server addresses can be set like this

Set-DnsClientServerAddress -InterfaceIndex 12 -ServerAddresses ‘’


The cmdlets are from the NetTCPIP and DnsClient modules respectively.


Written by richardsiddaway

May 12th, 2014 at 2:08 pm

Working with Server Core–Domain join

without comments

Windows Server can be installed in two ways – full fat GUI or Server Core.  The latter is Windows without Windows.  The GUI components are stripped off and you’re just left with the core components.  This results in a smaller server – I’ve got 2 machines running in my Hyper-V test environment. Both are set to use dynamic memory with 512MB startup RAM. The full GUI machine needs 1126MB while the Server Core version needs 566MB.

With Server Core all you get is a prompt for administration – unfortunately its cmd.exe but typing powershell starts PowerShell – including running a profile.

Without a GUI you need to use the command line to do everything – I’ll be doing my demos at the PowerShell Summit from Server Core machines so some things will have to wait until after then – and I’m going to do a series on posts on administering Server Core machines.

I’ve already shown you  how to test if your machine is activated.  This how you join it to the domain.

Make sure that the IP and DNS server addresses have been set so the machine can find a domain controller.

$cred = Get-Credential
Add-Computer -Credential $cred -DomainName sphinx -Restart

Create a credential for the account that can join the machine to the domain.  use Add-Computer and supply the credential and domain name. The –ReStart parameter forces a restart post domain join.

if you want to see the results of calling Add-Computer then drop the restart switch and use Restart-Computer whenever you want the restart to happen

Written by richardsiddaway

April 21st, 2014 at 11:48 am

Checking license activation

without comments

I’m building some virtual machines for my demo’s at the upcoming PowerShell summit.  To make the demo’s, and setup, more interesting(?) I decided to use some Server Core instances.

The usual setup activities become a bit more interesting with Server Core – particular Windows activation. 

Windows 2012 R2 will activate itself if the new machine has an Internet connection when it is created. With the GUI version of Windows you can check that Windows is activated using the System applet in Control Panel.

If you’re using Server Core you can use WMI to test activation:

Get-CimInstance -ClassName SoftwareLicensingProduct |
where PartialProductKey |
select Name, ApplicationId, LicenseStatus |
Format-List *

Use the SoftwareLicensingProduct WMI class and filter for PartialProductkey  – that means a product key has been entered. You can then select the name of the product the ApplicationId and the LicenseStatus:

Name          : Windows(R), ServerStandard edition
ApplicationId : 55c92734-d682-4d71-983e-d6ec3f16059f
LicenseStatus : 1

A License status of 1 indicates that its licensed – i.e. activated

More on using WMI to test and set activation in chapter 13 of PowerShell and WMI –

Written by richardsiddaway

April 13th, 2014 at 6:51 am