PowerShell Direct is a new feature provided by the next release of Windows Server that enables to run PowerShell commands from Hyper-V hosts in a virtual machine. It works without the network and so without WinRM or other features. This is great when a firewall is misconfigured or when a network issue occurs and avoids you to manage your server. In this topic I’ll configure the network configuration on a Nano Server that is not reachable.
I have deployed a Nano Server from the Technical Preview 3. In this version, network information can be displayed as below.
Before PowerShell direct, we ran Enter-PSSession cmdlet with ComputerName parameter to execute commands on a remote server. On the below screenshot, I’m connecting to my Nano Server called Nano01 (IP: 10.10.0.220). Note that credentials are required to open a remote PowerShell session.
Next I modify the address IP of Nano01 to make it unreachable from the network.
I run a ping and as you can see below, Nano01 is unreachable.
To finish I open the Nano01 console to verify the “bad” address IP.
Without PowerShell direct, it would be really difficult to regain control on your Nano Server because there is no shell even if you plug a screen on your server. But fortunately, we have PowerShell Direct.
In the next release of Windows Server, the Enter-PSSession cmdlet has a new parameter called VMName. So from your Hyper-V host you can run Enter-PSSession -VMName <VM Name> -Credential Get-Credential (you can also replace -VMName parameter by -VMGuid and specify the VM Guid). On the below screenshot, you can see that I’m connected to Nano01 with PowerShell direct. Note that credentials are also mandatory to open a remote PowerShell session though PowerShell Direct.
Then I run again a netsh command to change the IP Address of Nano01.
The Invoke-Command cmdlet has also the VMName parameter to run script blocks through PowerShell direct (VMGuid parameter is also available). In the below screenshot I used Invoke-Command cmdlet to change the DNS Server of Nano01.
I try again a ping to verify if I can connect to Nano01. Oh yeah it’s working J.