Customizing Nano deployment using SetupComplete.cmd

How to perform post deployment customization tasks for Nano Server using SetupComplete.cmd and PowerShell

Warning: Attempt to assign property of non-object in /home/techtho4/public_html/wp-content/plugins/wp-github/lib/github.php on line 274

Nano Server SetupComplete.cmd

While possible to set many options in the actual Nano Server image you will likely find yourself needing to perform a few post deployment customization tasks.  These can be accomplished through use of SetupComplete.cmd which can be found in: Windows\Setup\Scripts of your Nano image.

File Path Location of Nano Server SetupComplete.cmd file

If you prefer video format over written documentation I demonstrate use of SetupComplete.cmd to customize a Nano Server deployment in the following TechThoughts video:

Add custom tasks to SetupComplete.cmd

To access and edit the SetupComplete.cmd file simply mount your Nano image vhd/vhdx and navigate to:


Below you can reference an example of a SetupComplete.cmd that is setup to customize:

  • Enabling WinRM access to the Nano Server
  • Setting desired time zone
set SCLOG=%SystemRoot%\setup\scripts\setupcomplete.log
echo "Executing 'netsh advfirewall firewall add rule name='WinRM 5985' protocol=TCP dir=in localport=5985 profile=any action=allow'" >> %SCLOG%
netsh advfirewall firewall add rule name="WinRM 5985" protocol=TCP dir=in localport=5985 profile=any action=allow >> %SCLOG%
echo "Executing 'netsh advfirewall firewall set rule group='@FirewallAPI.dll,-29252' new enable=Yes'" >> %SCLOG%
netsh advfirewall firewall set rule group="@FirewallAPI.dll,-29252" new enable=Yes >> %SCLOG%
echo "Executing 'tzutil.exe /s 'Central Standard Time''" >> %SCLOG%
tzutil.exe /s "Central Standard Time" >> %SCLOG%

As you can see in this example it is possible to customize your Nano Server deployment within SetupComplete.cmd with basic windows shell commands.

In my opinion PowerShell is a lot more flexible and robust then shell scripting so I create a NanoSetup.ps1 script with my desired customizations and have SetupComplete.cmd run my custom PowerShell script.

Use SetupComplete.cmd to run custom PowerShell scripts

Add the following code to the bottom of your SetupComplete.cmd file:

REM The following lines of code will allow the Nano Server to run the NanoSetup.ps1 script on startup
PowerShell "Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser -Force"
PowerShell ". C:\Windows\Setup\Scripts\NanoSetup.ps1"

The above example will run the NanoSetup.ps1 script on startup which contains all desired post configuration tasks.

Note that NanoSetup.ps1 has to be copied to the Nano Server image.

Unless you have reasons to do otherwise I find it’s simplifies things keeping all customization tasks in the same location – [MountedDriveLetter]:\Windows\Setup\Scripts

With your SetupComplete.cmd file edited and your custom PowerShell script completed and copied over you should be set to test your post deployment process.

If (as in my example) your PowerShell script will be joining your Nano Server to a domain you have an additional step: Generate the domain blob file.

  1. From a DC on the domain you will be joining create a new computer object with the same hostname as your new Nano Server
    • This AD object must not have been used previously for this to work
  2. On the same DC run the following:
    • djoin.exe /provision /domain yourdomain.local /machine MachineName /REUSE /savefile .\odjblob
  3. Copy the domain odjblob file to your nano server scripts folder or another location that your PS script will be referencing

Make sure to dismount your Nano Server vhd/vhdx and once it is deployed StartupComplete.cmd will execute on first run, and if you specified, will kick off your custom PowerShell script as well.

You can find my full example of a working SetupComplete.cmd and my custom PowerShell script on the TechThoughts GIT:

I have included a link to the custom NanoSetup.ps1 script for you to easily review what custom tasks you could potentially perform:


1 Trackback / Pingback

  1. How to create a Nano Server Image - Tech Thoughts

Leave a Reply

Your email address will not be published.