You dont have javascript enabled! Please enable it!

How To Set DNS Server Address on Nano Server using PowerShell DSC #NanoServer #PowerShell #DSC

3 Min. Read

Hello folks,

As we are approaching the holidays and being busy preparing for Christmas and New Year! I thought let’s end-up the year with a Nano gift J

In the previous post, I showed you step by step on how to run a Hyper-V Cluster on Nano Server.

In today’s blog post, we will set the DNS server address on all Nano Servers using PowerShell Desired State Configuration.

As you might know, Microsoft added new packages into Nano Server in Windows Server 2016 Technical Preview 4.

At the time of writing this post, here is the list of current packages (roles and features) for your reference:

  • Microsoft-NanoServer-Compute-Package
  • Microsoft-NanoServer-Containers-Package
  • Microsoft-NanoServer-DCB-Package
  • Microsoft-NanoServer-Defender-Package
  • Microsoft-NanoServer-DNS-Package
  • Microsoft-NanoServer-DSC-Package
  • Microsoft-NanoServer-FailoverCluster-Package
  • Microsoft-NanoServer-Guest-Package
  • Microsoft-NanoServer-IIS-Package
  • Microsoft-NanoServer-NPDS-Package
  • Microsoft-NanoServer-OEM-Drivers-Package
  • Microsoft-NanoServer-Storage-Package
  • Microsoft-OneCore-ReverseForwarders-Package
  • Microsoft-Windows-Server-SCVMM-Compute-Package
  • Microsoft-Windows-Server-SCVMM-Package

For the purpose of this demo, all you need to do is:

1. Mount the ISO of Windows Server 2016 TP4 installation media.
2. Change to “NanoServer” directory on the TP4 installation media.
3. Import NanoServerImageGenerator.psm1 module.
4. Create Nano image that contains DSC package (you can add other roles if you need to).
5. Create NanoServer Virtual Machines.
6. Download and import xNetworking PowerShell DSC Module.
7. Push the DSC configuration to set the DNS Server.

I am running all the following scripts from PowerShell console as Administrator on Windows Server 2016 Hyper-V TP4 host domain joined and not from PowerShell ISE.  

Step 1: Create Nano Server Image
In this step, I will combine point 1 through 4 in one script:

$ServerISO = "C:\10586.0.151029-1700.TH2_RELEASE_SERVER_VOL_X64FRE_EN-US.ISO"
Mount-DiskImage $ServerISO
$DVDDriveLetter = (Get-DiskImage $ServerISO | Get-Volume).DriveLetter 

Import-Module C:\NanoServer\NanoServerImageGenerator.psm1 -Verbose
$Password = ConvertTo-SecureString -String "P@ssw0rd" -AsPlainText -Force

$IP = 140
1..4 | % {
         New-NanoServerImage -MediaPath "$($DVDDriveLetter):" `
                    -BasePath C:\NanoServer\ `
                    -TargetPath $("D:\Hyper-V\NANO-0$_\" + "NANO-0$_" + ".vhdx")`
                        -ComputerName $("NANO-0$_") `
                        -AdministratorPassword $Password `
                        -InterfaceNameOrIndex Ethernet `
                    -Ipv4Address 192.168.1.$IP `
                    -Ipv4SubnetMask `
                    -Ipv4Gateway `
                    -DomainName `
                    -Clustering `
                    -GuestDrivers `
                    -Storage `
                    -Packages Microsoft-NanoServer-Compute-Package, Microsoft-NanoServer-DSC-Package `

Dismount-DiskImage $ServerISO

If you noticed in above script, we are able to inject the IPv4Address, IPv4SubnetMask and IPv4Gateway. Unfortunately, the DNS Server address is not injected at the time of image creation, this parameter is not included yet in Nano PowerShell module in TP4. The DNS Server is very important when Nano Server is joined to the domain.

Step 2: Create Nano Virtual Machines

In this step, I will create 4 Nano Virtual Machines.

$vSwitchName01 = "NAT_vSwitch"
$InstallRoot = "D:\Hyper-V"

1..4 | % {
New-VHD -Path ($InstallRoot + "\NANO-0$_\NanoServer_D.vhdx") -SizeBytes 50GB -Dynamic
New-VM -VHDPath ($InstallRoot + "\NANO-0$_\NANO-0$_.vhdx") -Generation 2 -MemoryStartupBytes 4GB -Name NANO-0$_ -Path $InstallRoot -SwitchName $vSwitchName01

Set-VMProcessor -VMName NANO-0$_ -Count 4
Set-VM -VMName NANO-0$_ -AutomaticStopAction ShutDown -AutomaticStartAction StartIfRunning
Enable-VMIntegrationService NANO-0$_ -Name "Guest Service Interface"

Rename-VMNetworkAdapter -VMName NANO-0$_ -NewName "MGMT"
Set-VMNetworkAdapter -VMName NANO-0$_ -Name "MGMT" -DeviceNaming On

Add-VMScsiController -VMName NANO-0$_
Add-VMHardDiskDrive  -VMName NANO-0$_ -ControllerType SCSI -ControllerNumber 1 -ControllerLocation 0 -Path ($InstallRoot + "\NANO-0$_\NanoServer_D.vhdx")

Start-VM -Name NANO-0$_ | Out-Null

Step 3: Download and Import DSC xNetworking Module

In this step, I will download and import the xNetworking module which is a part of the DSC Resource Kit produced by the PowerShell Team. This module contains the xIPAddress and xDnsServerAddress resources that allow configuration of a node’s IP Address and DNS Server Address.

# Download xNetworking module from PSGallery
Save-Module -Name xNetworking -Path C:\
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Install-Module -Name xNetworking

# Copy xNetworking Module to all Nano Servers
$LocalPassword = ConvertTo-SecureString -String "P@ssw0rd" -AsPlainText -Force
$LocalCred = New-Object System.Management.Automation.PSCredential (".\Administrator", $LocalPassword)
$IP = 140
1..4 | % {
$S1 = New-PSSession -ComputerName 192.168.1.$IP -Credential $LocalCred 
Copy-Item -Path C:\xNetworking -ToSession $S1 -Destination "C:\Program Files\WindowsPowerShell\Modules" -Recurse -Force
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Install-Module -Name xNetworking

In the first part of the script, I downloaded the module from PowerShell gallery locally and then I copied it through PowerShell remote session to all Nano Servers instead of download it again from the Internet. This is just awesome.

In PowerShell V5.0, you can copy and send files over PowerShell remote session without the need to use network shares!

As a side note, Windows Management Framework (WMF) 5.0 is now available which is bring support for all the goodness of PowerShell V5.0 to down-level OS (Windows Sever 2012 R2, Windows Server 2012, Windows Server 2008 R2 SP1, Windows 10 Version 1511, Windows 8.1 and Windows 7 SP1).

How To Set DNS Server Address on Nano Server using PowerShell DSC #NanoServer #PowerShell #DSC 2

Step 4: Push DSC Configuration

Before we push the DSC configuration and set the DNS server, I will pull the current DNS address from each Nano Server.

As you can see, we don’t have any IP Address set yet.

How To Set DNS Server Address on Nano Server using PowerShell DSC #NanoServer #PowerShell #DSC 3

I will push the DSC configuration now to all Nano machines.

# Push DSC Configuration
$LocalPassword = ConvertTo-SecureString -String "P@ssw0rd" -AsPlainText -Force
$LocalCred = New-Object System.Management.Automation.PSCredential (".\Administrator", $LocalPassword)
$DNSServerAddress = ""
.\SET-DNSAddress.ps1 -targetNode NANO-01,NANO-02,NANO-03,NANO-04 -DNSServerAddress $DNSServerAddress


configuration xDnsClient
    # Importing the resource from custom DSC Module
    Import-DscResource -ModuleName xNetworking

    # List of Nano machine which needs to be configured
    node $targetNode
        # Set the DnsServerAddress for given interface
        xDNSServerAddress dnsServer
            Address        = $dnsServerAddress
            AddressFamily  = 'IPv4'
            InterfaceAlias = 'Ethernet'


Start-DscConfiguration -Path xDnsClient -Verbose -Wait -ComputerName $targetNode -credential $LocalCred -Force

How To Set DNS Server Address on Nano Server using PowerShell DSC #NanoServer #PowerShell #DSC 4

Count until 5… and Boom!

How To Set DNS Server Address on Nano Server using PowerShell DSC #NanoServer #PowerShell #DSC 5

Last but not least, let’s confirm the DNS address is set on all Nano machines.

Yes indeed!

How To Set DNS Server Address on Nano Server using PowerShell DSC #NanoServer #PowerShell #DSC 6

With that I will sign-off for 2015.

I want to thank the Community, Followers, Readers, Microsoft Product Teams, MVP Award Program, MVP’s, Developers and ITPro’s!

Until then… see you in 2016…

Happy Holidays!


How To Set DNS Server Address on Nano Server using PowerShell DSC #NanoServer #PowerShell #DSC 7

Photo of author
About the Author
Charbel Nemnom
Charbel Nemnom is a Senior Cloud Architect, Swiss Certified ICT Security Expert, Certified Cloud Security Professional (CCSP), Certified Information Security Manager (CISM), Microsoft Most Valuable Professional (MVP), and Microsoft Certified Trainer (MCT). He has over 20 years of broad IT experience serving on and guiding technical teams to optimize the performance of mission-critical enterprise systems with extensive practical knowledge of complex systems build, network design, business continuity, and cloud security.

Related Posts


StarWind News 15th December 2015 @starwindsan

Holiday Gift for the IT Community #SkillUP #IT @PacktPub


Let me know what you think, or ask a question...

error: Alert: The content of this website is copyrighted from being plagiarized! You can copy from the \'Code Blocks\' in \'Black\' by selecting the Code. Thank You!