Windows 2012 R2

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 10.10.54.0 -IPAddress 10.10.54.2 -ClientId 00155D36C906 -Description "LInux machine" -Name "SphinxLX01"

 

The clientid is the VMs MAC address.

 

You can view the current reservations:

 

£> Get-DhcpServerv4Reservation -ScopeId 10.10.54.0 | fl *


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

 

You can view current leases:

£> Get-DhcpServerv4Lease -ScopeId 10.10.54.0 | fl *


IPAddress             : 10.10.54.2
ScopeId               : 10.10.54.0
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              : 10.10.54.201

 

And all from the comfort of your very own PowerShell prompt

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 10.10.54.201

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 10.10.54.2 -EndRange 10.10.54.30 -Description "Scope for Manticore domain" -Type DHCP -State Active -SubnetMask 255.255.255.0 -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 10.10.54.0 | fl

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

Patching Server Core

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

http://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc

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

Installing Centos in Windows 2012 R2 Hyper-V

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

Formatting disks – – the new way

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.

Working with Server Core–renaming the machine

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.

Working with Server Core–setting IP addresses

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 '10.10.55.101' -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 '10.10.55.101' -AddressFamily IPv4 -PrefixLength 24 -DefaultGateway '10.10.55.01'

 

The DNS server addresses can be set like this

Set-DnsClientServerAddress -InterfaceIndex 12 -ServerAddresses '10.10.55.100'

 

The cmdlets are from the NetTCPIP and DnsClient modules respectively.

THESE MODULES ARE ONLY AVAILABLE ON WINDOWS 8/2012 AND LATER.

Working with Server Core–Domain join

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

Checking license activation

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

Windows Server 2012 R2 Update

The Windows Server 2012 R2 Update (and the corresponding Windows 8.1 Update) are available to MSDN/TechNet subscribers. General availability follows on 8 April (patch Tuesday)

Details from http://blogs.technet.com/b/windowsserver/archive/2014/04/02/windows-server-2012-r2-update-is-now-available-to-subscribers.aspx