header image

Archive for Windows 2012 R2

Creating DNS records

Posted by: | October 30, 2015 Comments Off on Creating DNS records |

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 = ‘Manticore.org’

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

  $octs = $ipaddress -split ‘\.’

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


under: DNS, PowerShell, Windows 2012 R2

Creating a DHCP reservation

Posted by: | September 20, 2014 Comments Off on Creating a DHCP reservation |

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

under: DHCP, PowerShell v4, Windows 2012 R2

Authorising a DHCP server and creating a scope

Posted by: | September 7, 2014 Comments Off on Authorising a DHCP server and creating a scope |

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 server02.manticore.org -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

under: DHCP, PowerShell v4, Windows 2012 R2

Patching Server Core

Posted by: | August 28, 2014 | No Comment |

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

under: PowerShell, Windows 2012 R2

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
under: Virtualization, Windows 2012 R2

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.

under: Windows 2012 R2, Windows 8, Windows 8.1, Windows Server 2012

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.

under: PowerShell V3, PowerShell v4, Windows 2012 R2, Windows Server 2012

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.


under: Networking, PowerShell V3, PowerShell v4, Windows 2012 R2, Windows Server 2012

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

under: PowerShell V3, PowerShell v4, Windows 2012 R2, Windows Server 2012

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 – www.manning.com/siddaway2

under: PowerShell and CIM, PowerShell and WMI, PowerShell V3, PowerShell v4, Windows 2012 R2, Windows Server 2012

Older Posts »