How to display ipconfig on Nano Server every time it boots
When you read through the “Getting Started with Nano Server” guide, you’ll come across SetupComplete.cmd and you’ll appreciate that you can display ipconfig on first boot. But that’s really not enough. I want to display ipconfig (and possibly other things) *every* single time Nano Server boots. Here’s how to do it:
This blog post assumes that you’ve already built your Nano Server image and added your favorite roles, but have not yet booted it.
Create 2 command files with the following content:
schtasks /create /tn "Start" /tr c:\windows\system32\Startup.cmd /sc onstart /ru "System"
ping 188.8.131.52 –n 7
SetupComplete.cmd executes only on first boot, so what we’re doing is scheduling a task which executes on start:
/tn: Task name
/tr: Task run – the task to run
/sc: schedule – in our example, OnStart, i.e. on every boot
/ru: Run as – in our case, as “System” – very important!
Startup.cmd will be run on every boot. I had to introduce an artificial delay (ping), because apparently, Nano Server starts too fast J - go ahead and experiment with this delay, and see if you need it in your scenario.
Of course, you can replace ipconfig with any command you want, but remember that anything that scrolls off the screen cannot be retrieved. J
Mount the image:
dism /Mount-Image /ImageFile:.\nanoServer.vhd /Index:1 /MountDir:.\mountdir
Copy SetupComplete.cmd to the image:
copy .\SetupComplete.cmd .\mountdir\Windows\Setup\Scripts
Copy Startup.cmd to the image:
copy .\Startup.cmd .\mountdir\Windows\System32
Unmount the image:
dism /Unmount-Image /MountDir:.\MountDir /Commit
Give it a try and let us know what you think.