PowerShell version 5 comes with a lot of features that Nano Server benefit from. The main feature are:
If you want to manage your Nano Server right now, you can use PowerShell Remoting or if your Nano Server is running in a Virtual Machine you can also use PowerShell Direct which is covered in Chapter 4, Saving Time and Cost with Hyper-V Automation.
In order to manage Nano server installation using PowerShell remoting, carry out the following steps:
net start WinRM
Set-Item WSMan:localhostClientTrustedHosts -Value "servername or IP"
Set-Item WSMan:localhostClientTrustedHosts -Value "servername or IP, servername or IP"
You can also set it to allow it to connect to a specific network subnet using the following command:
Set-Item WSMan:localhostClientTrustedHosts -Value 10.10.100.*
Test-WSMan -ComputerName "servername or IP" -Credential servernameAdministrator -Authentication Negotiate
Enter-PSSession -ComputerName "servername or IP" -Credential servernameAdministrator
#region Variables $NanoSRV = 'NANOSRV-HV01' $Cred = Get-Credential "DemoSuperBook" $Session = New-PSSession -ComputerName $NanoSRV -Credential $Cred $CimSesion = New-CimSession -ComputerName $NanoSRV -Credential $Cred $VMTemplatePath = 'C:Temp' $vSwitch = 'Ext_vSwitch' $VMName = 'DemoVM-0' #endregion Get-ChildItem -path $VMTemplatePath -filter *.VHDX -recurse | ` Copy-Item -Destination D: -ToSession $Session 1..2 | % { New-VM -CimSession $CimSesion -Name $VMName$_ -VHDPath "D:$VMName$_.vhdx" -MemoryStartupBytes 512MB ` -SwitchName $vSwitch -Generation 2 Start-VM -CimSession $CimSesion -VMName $VMName$_ -Passthru }
In this script, we created a PowerShell session and a CIM session to Nano Server, then we copied VM Templates from the management machine to Nano Server, when the copy is done, we created two Generation 2 VMs and finally started them up.
After a couple of seconds, we launched Hyper-V Manager console and observed the new two VMs running on Nano Server host, as shown in the following screenshot:
As mentioned earlier, if you have installed Nano Server in a Virtual Machine running on a Hyper-V host, you can use PowerShell Direct to directly connect from your local Hyper-V host to your Nano Server VM using the following command:
Enter-PSSession -VMName "VMName" -Credential servernameAdministrator
Moreover, if you have Nano Server as a Hyper-V host, as shown in the preceding example, you could use PowerShell remoting to connect to Nano Server from your management machine and then leverage PowerShell Direct to manage your virtual machines, welcome to Nested PowerShell Remoting (PSRemoting + PSDirect).
To do this use the following command:
#regionVariables $NanoSRV = 'NANOSRV-HV01' #Nano Server name or IP address $DomainCred = Get-Credential "DemoSuperBook" $LocalCred = Get-Credential "~Administrator" $Session = New-PSSession -ComputerName $NanoSRV -Credential $DomainCred #endregion Invoke-Command -ComputerName $NanoSRV -Credential $DomainCred -ScriptBlock { param ($LocalCred) Get-VM Invoke-Command -VMName (Get-VM).Name -Credential $LocalCred -ScriptBlock { hostname;Tzutil /g} } -ArgumentList $LocalCred
In this script, I established a PowerShell session into Nano Server host, and then I used PowerShell Direct to query all VMs and get their hostnames and time zones.
Here is the output:
3.133.147.87