Monthly Archive


Monthly Archives: October 2015

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 = ''

  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


Create a reverse lookup zone

I needed to create a DNS reverse lookup zone for my test environment. With Windows Server 2012 R2 I’ve got cmdlets available for managing DNS servers – the DnsServer module. You need to install the DNS role or the DNS RSAT tools to get access to the module.


To create a new reverse lookup zone

Add-DnsServerPrimaryZone -DynamicUpdate Secure -NetworkId '' -ReplicationScope Domain


Use the netorkId to define the subnet the zone spans. Setting DynamicUpdate to Secure ensures I have an AD integrated zone and I’ve set the replication scope to the domain.


Doesn’t get any easier

Win free entry to the PowerShell Summit

Want to go to the PowerShell Summit? Want to go for free?


You can win free entry to the Summit (need to pay your own travel & hotel) through the competition at

-in operator

As an alternative to the –contains operator you can use the –in operator


Repeating the tests from the previous post on –contains


PS> $primes = 1,3,5,7,11,13,17,19,23,29,31,37,41,43,47
PS> $candidate = 7
PS> $candidate -in $primes

PS> $candidate = 4
PS> $candidate -in $primes


The –in operator can be used in the simplified where syntax but –contains can’t

-contains operator

Sometimes you may want to test if a value is in a collection of values


For instance

$primes = 1,3,5,7,11,13,17,19,23,29,31,37,41,43,47


if you want to test if 7 is a member of the collection

$candidate = 7
$primes -contains $candidate


Likewise testing 4

$candidate = 4
$primes -contains $candidate

DSC resource kit update–October 2015

The DSC resource kit is the primary place to look for DSC resources beyond those baked into Windows.


An update to the resources in the kit has been announced. Some new resources and lots of bug fixes.



for details

Testing connectivity before Invoke-Command

A question on the forum asked about testing if a remote machine could be reached before using Invoke-Command against it.


The usual way to test if you can reach a remote machine is to ping it

PS> Test-Connection -ComputerName $env:COMPUTERNAME -Quiet


That shows you can reach the machine but it doesn’t mean that you can use Invoke-Command to send a request.

I think a better test is to use Test-WSMan


It will test if the WinRm service is running (won’t test if remoting is enabled)


$computers = "$env:COMPUTERNAME", 'NotFound'

foreach ($computer in $computers){
    $target = $computer
    if (Test-WSMan -ComputerName $computer -ErrorAction Ignore) {
        Invoke-Command -ComputerName $computer -ScriptBlock {Get-Service}
    else {
        Write-Warning -Message "Couldn't connect to $computer"



You can push the output to file or put the unreachable machine names into a file if you need to record them.

UK PowerShell User Group

Two meetings of the UK PowerShell group have been announced


Tuesday 24 November in Manchester


Thursday 26 November at Rackspace, in Hayes Middlesex


Details from


There is a rumour that I might be speaking at the 26 November event

PowerShell and SSH

The PowerShell team have announced the availability of OpenSSH 7.1 for Windows -


This is their first step in bringing SSH support into PowerShell.


The roadmap for next steps is available on their blog at the link above

PowerShell resources–you tube

One place you might not think of looking for PowerShell resources is you tube. has its own channel on you tube - - where we’ve posted the session recordings from:

PowerShell Summit Europe 2015

PowerShell summit Europe 2014

PowerShell Summit NA 2015


selected sessions from

PowerShell Summit NA 2014 and

PowerShell Summit NA 2013

are also available.


In addition we have a number other recordings available.