The last couple of weeks I delivered several custom PowerShell trainings and playing with PowerShell gave me the idea to write something about one om my favorite new features of Windows Server 2016 and Windows 10….. namely PowerShell direct. Actually you can also say that it is a new Hyper-V option… First of all PowerShell is getting more and more important and I experienced that my students got more and more enthusiastic once they saw the possibilities PowerShell offers.
Ok, PowerShell direct offers you the option to connect from a Hyper-V host to a VM on that host using for instance PowerShell remoting. There are also other commands you can use that are using PowerShell direct and that are not PSRemoting cmdlets. When you use PSRemoting cmdlets, the WinRM service does not have to run. PowerShell remoting and the possibilities it offers is probably the most powerful feature of PowerShell there is in my opinion. With PowerShell direct you can connect to your VM, configure what you want on the VM, without using a GUI.
First let’s look at the prerequisites, when will this work for you.
- You need to be a Hyper-V admin
- Hyper-V host OS must be Server 2016 TP or higher or Windows 10
- You have to have rights on the VM guest.
- The VM guest have to run Window Sever 2016 TP or Windows 10
- The VM has to be turned on.
Comands you can use:
- Enter-PSSession –> An interactive connection to the VM, one at a time
- Invoke-Command –> A connection to one or many VM’s, where you connect, run what you need to and disconnect, parallel to each other.
- PowerShell direct enabled commands
Which command you want to use is up to you and depending on the situation. Use Get-Help to find out what the commands are capable off. We do not have to use the PSRemoting commands to get something done to the VM, that is all depending what you want to do. As I said before there are more commands available that also use powershell direct.
First I will show an example with Enter-PSSession. In this example I will install the windows feature Print Server on a VM, check if installation was succesfull and disconnect.
Step 1: connect to the VM
Step 2: install the windows feature and disconnect the session
To illustrate the PowerShell direct using a non PSRemoting command I will add a network card to a newly build VM and connect it to a virtual switch.
Step 1: Check which network adapter(s) are connected to the VM
Step2: Add a network adapter and after that check if all went well
As you can see 2 ways to easily do something to a VM without a GUI. To me a big step ahead for managing Hyper-V Guests.
Please experiment with PowerShell direct to find out what it can do for you!
Thanks for reading.