Nano Server notes, Part 2

By | May 3, 2016

Fixing the time zone in a “new” Windows VM guest always bugs me. This is one of those pet-peeves that fortunately only has to be fixed once. Changing the time zone in Windows was designed for the real world, where a mobile device physically changes time zones; Windows just changes the UTC-offset. In the virtual world, guests often start with the host time, but not the host’s UTC-offset; for new Windows VM guests that assume the BIOS clock is local time, we have to change both. Actually, the local time is correct and changing the UTC-offset messes up the time. Here’s the oddity looking at a new Nano Server image remotely; even though the result of the Get-Date command says one thing, after a reboot it says another.

Nano-Server-TZUtil-Change

I use VirtualBox; the workaround is to shutdown the guest and then start it again to re-sync the BIOS clock to the host.

This annoyed me a long time ago — I often ran into this issue when booted into WinPE which has the same Pacific Time default — so, I added a routine to a program that saves the local time and re-sets it in between the time-zone change. Somebody out there (probably many) has a PowerShell script that does this, but manually resetting the local time does seem to have a side-effect on Get-Date.

Nano-Server-GuestVM-TZFix

CR-LF: powershell.exe vs. wsmprovhost.exe

Speaking of PowerShell, this is another oddity/inconsistency: console output is reformatted differently in remote PowerShell sessions. Remote sessions — in Nano Server being hosted in a wsmprovhost.exe process — seem to be converting carriage-return characters (‘\r’) to line-feeds (‘\n’); the way this manifested for me was a lot of lines ending with the typewriter CR-LF sequence displayed as LF-LF. This is different than a local PowerShell session hosted in a powershell.exe process, which behaves more like the Windows console shell. The CR character is rarely necessary, but I did find that the auditpol utility was using CRLFs like I was. These screenshots show the local powershell display from Windows 10 on the left and the remote wsmprovhost.exe display from Nano Server on the right.

Auditpol.exe output in local Powershell

Auditpol.exe output in local Powershell

Auditpol.exe output in remote PSSession (wsmprovhost)

Auditpol.exe output in remote PSSession (wsmprovhost)

“There’s nothing new under the sun,” but it took longer than I thought to find a thread on Stack Overflow that described this and I didn’t find a definitive workaround. That’s probably more because I need to keep improving my PowerShell; for now, I came up with a kludgy workaround for remote sessions into Nano Server VMs: store the stdout and stderr output in a local variable, and then do string replacements in sequence and write out the result to the console.

$result = & "<command-in-double-quotes>" <command parameters> 2>&1 | Out-String
$result.Replace("`r`n","`n").Replace("`n`n","`n")

In the case of displaying auditpol options:

$result = & "auditpol.exe" /? 2>&1 | Out-String
$result.Replace("`r`n","`n").Replace("`n`n","`n")