Official PS Direct documentation is located here (https://msdn.microsoft.com/en-us/virtualization/hyperv_on_windows/user_guide/vmsession.html).
At Ignite we announced PowerShell Direct, and briefly demoed it’s capabilities in the “What’s New in Hyper-V” session. This is a follow up so you can get started using PowerShell Direct in your own environment.
What is PowerShell Direct?
It is a new way of running PowerShell commands inside a virtual machine from the host operating system easily and reliably.
There are no network/firewall requirements or configurations.
It works regardless of Remote Management configuration.
You still need guest credentials.
For people who want to try it out immediately, go ahead and (as Administrator) run either of these commands on a Windows10 Hyper-V host where VMName refers to a VM running Windows10:
Enter-PSSession -VMName VMName
Invoke-Command -VMName VMName -ScriptBlock { Commands }
*** Note: This only works from Windows 10/Windows Server Technical Preview Hosts to Windows 10/Windows Server Technical Preview guests.
Please let me know what guest/host operating system combinations you’d like to see and why.
Here is why I think this is really cool
Honestly, because it’s incredibly convenient. I’ve been using PowerShell Direct for everything from scripted virtual machine configuration and deployment where each virtual machine has different roles and requirements through checking the state of my virtual machine (aka, has the guest operating system booted yet?).
Today, Hyper-V administrators rely on two categories of tools for connecting to a virtual machine on their Hyper-V host:
- Remote management tools such as PowerShell or Remote Desktop
- Hyper-V Virtual Machine Connection (VM Connect)
Both of these technologies work well but have tradeoffs as the Hyper-V deployment grows. VMConnect is reliable but hard to automate while remote PowerShell is a brilliant automation and scripting tool but can be difficult to maintain/setup in some cases. I sometimes hear customers lament domain security policies, firewall configurations, or a lack of shared network preventing the Hyper-V host from communicating with the virtual machines running on it.
I’m also sure we’ve all had that moment where you're using remote PowerShell to modify a network setting and accidently make it so you can no longer connect to the virtual machine in the process…I know I have.
PowerShell Direct provides the scripting and automation experience available with remote PowerShell but with the zero configuration experience you get through VMConnect.
With that said, there are some PowerShell tools not available yet in PowerShell Direct. This is the first step. If you expected something to work and it didn’t, leave a comment.
Getting started and a few common issues
I decided to make a picture of the most basic usage imaginable.
.5 – Dependencies
You must be connected to a Windows 10/Windows Server Technical Preview Host with Windows 10/Windows Server Technical Preview virtual machine(s).
You need to be running as Hyper-V Administrator (launch PowerShell as Administrator).
You need user credentials in the virtual machine.
The virtual machine you want to connect to must be running locally (on this host) and booted.
I use Get-VM as a sanity check.
1 – Enter-PSSession -VMName works. So does Enter-PSSession –VMGuid
Enter-PSSession -VMName VMName
Notice this is an interactive session. I am running PowerShell commands on the virtual machine directly (same behavior as Enter-PSSession usually has).
2 – Invoke-Command -VMName works. So does Invoke-Command -VMGuid
Invoke-Command -VMName VMName -ScriptBlock { Commands }
Notice this locally interprets the command(s) or script you pass in then performs those actions on the virtual machine (same behavior as Invoke-Command usually has).
It's that easy.
I look forward to seeing what you all build with this tool! Happy scripting.
Cheers,
Sarah
Edit: Read more here https://msdn.microsoft.com/virtualization/hyperv_on_windows/user_guide/vmsession
I’d like to see this feature supported with Windows 2012 and Windows 2012 R2 guests. It will open up many automation scenarios that may not be immediately possible on Windows Server vNext. Primarily because not all software will support Windows Server
vNext on release. I sure hope they will but reality doesn’t always line up like that.
Samir/Robert: Thank you for the feedback about guest OSes you’d like to connect to!
Robert: Right now it is host -> guest only (physical machine to VMs on that machine). The VMs can be in a cluster but they have to physically be located on that node. I’m aware of some guest <-> guest scenarios and some guest -> host scenarios. I’m interested
in hearing your particular use case?
Bhargav: Thanks for the feedback!
aL: I definitely want to have full session support so you can run get and new etc :). I’m glad someone mentioned it. You want this to use copy item….any other expected workflows you wish worked?
Nano Server and Nano Server VMs don’t work currently but get-vm should list the Nano VM…I’ll have to look into that.
Did you launch PowerShell as Administrator?
I’m running on W10 10074 with Hyper-V activated, two VMs running with Nano Server and WS2016TP2 but using Get-VM I get nothing. Any idea?
Since W10 10074 VMs hosted on Win 8.1 Pro Client-Hyper do not work in enhanced session mode (get disconnected every few seconds) and Win 8.1 Pro does not support this feature… 😉 Maybe supporting Win 8.1 Pro Client Hyper-V makes sense..
Hi Sarah.
Great presentation at Ignite! PowerShell Direct is a very nice feature. I cannot wait to see this also available in Nano Server to help in configuring IP on Nano in particular.
P.S. My Get-VM on Windows 10 Build 10074 correctly shows all my VM.
Ps direct is really cool but can you please also support making a possession without entering it? that way it could be used with the new copy-item -To/FromSession
208 Microsoft Team blogs searched, 49 blogs have new articles. 142 new articles found searching from
This is among the best useful management feature.
I think that enabling this feature to support Windows Server 20122012 R2 guest OS will be great. Because, by the GA of Windows Server 2016, Windows 20122012 R2 will be the V-1 Windows server OS, so it will be mostly used. In addition, with the end of life
of windows server 2003 next july, customers obviously plan to migrate their workloads to the last version, that is said, Windows server 2012 R2.
I’d really like to see a way to use this from server 2016 hosts to guest server 2012 machines. Maybe an add-on for 2012?
Is this going to support access from the guest OS back to the host as well? I can think of some situations where I’d like to be able to do that in my on-premise environment.
Will this work across clusters? or just on the guests inside the host?
Will we be able to PowerShell from guest to guest?
Please add support for 2008 R2 and 2012 R2, I work in the hosting space, so we have customer who still ask for 2008 R2 OS, even though if they gave me a chance I could get them running in 2012 R2. I need the automation to be available on older OS’s. This
would be useful to me not just for initial deployment but for ongoing maintenance.
"’m running on W10 10074 with Hyper-V activated, two VMs running with Nano Server and WS2016TP2 but using Get-VM I get nothing. Any idea?"
Are you sure you run PowerShell as administrator (elevated privileges)?
Hi Sarah!
My problem is my virtual machine and my server are not on the same domain.
Do you know if it’s possible to execute the server shell from my virtual machine?
This would do useful toward me not just for initial deployment but for ongoing maintenance. Please add support for 2008 R2 and 2012 R2, I work in the hosting space, so we have customer who still ask for 2008 R2 OS, even though if they gave me a chance
I could get them running in 2012 R2. I need the automation through live available on older OS’s.
Eduardo: As long as your VM is running on the same machine (aka you’re running PowerShell on the physical host on which the VM is located), you can use PowerShell direct. The domain, network, etc. do not matter.
We have been asking for this for some time. Add support for Windows Server 2008R2 or higher. Is it possible to also support linux VM so we can run a commands on a linux VM?
Also is there plan for something similar to automate running commmands on Azure Virtual Machines?
Would like to see this on 2016 Hosts and 2012 Guests, will unlock a lot for: Service Providers / Hosters / Shared Service scanarious.
This is compatible across all guest-host combinations where both are later than Windows 10. In other words, Server 16 hosts can use PowerShell Direct to manage Win10 and Server 16 guests.
No comment on Azure or Linux but thank you :). I know those would be helpful scenarios.
This feature is awesome, I do a lot test labs and forever making changes to VMs.. however I think backward compatibility to Server 2012 at least R2 version will be a big win for many people.. please please please look at this… you will make many people
happy!
Am I doing something wrong here…. I am using Windows 10 Enterprise with a Server "10" TP2 VM… when I try and run either of the commands I get prompted for the credentials… I enter the credentials of the VM’s Local Admin account (the only account
on there as not domain joined) and the Powershell session just sits there.. nothing happens.. I am running powershell as administrator.
Any Ideas?
Hey Sam Sam,
We changed the way we handle credentials between TP2 and TP3 so there may be an unfortunate build-to-build break.
Microsoft l’avait promis pour l’été, voici la Technical Preview 3 pour Windows Server 2016. Cette version intègre notamment les conteneurs tant attendus. La Technical Preview disponible au format ISO et VHD pour les .
Hi Sarah.
I’m so looking forward to this! Any there will be "DSC Direct"?
Hi Sarah,
This feature is awesome, but I too would love to see this functionality extended to the New-PSSession cmdlet. I’ve put a suggestion up on PowerShell Connect, so hopefully it’ll get noticed
Sarah,
This is a great new feature, that will help solve many challenges with automated builds and with troubleshooting.
But in large enterprises and hosted environments, the people who administer the virtual machines are not the same people that administer the virtual hosts. We need to be able to grant rights to connect to the virtual machine through the host, without granting
any other rights on the host.
Thanks
Technically very cool, but could you expand on the security implications? It seems like all options to prevent this like disabling remoting, or firewall rules have been bypassed. This must have been discussed. What was the consensus?
how can one get more hyper-v replication frequency example to configure it for 60 min instead of 15
Mike K — we discussed the security implications in depth. First, we’re using authentication against guest credentials so it is an authenticated connection with logging tied to the user account. Second, you can disable it in the guest and from the host.
There is a guest service much like an integration service (see this article
https://msdn.microsoft.com/virtualization/hyperv_on_windows/user_guide/managing_ics ) and WMI controls in the host. I’ll have to look up the exact WMI. When I do, I’ll update this doc
https://msdn.microsoft.com/virtualization/hyperv_on_windows/user_guide/vmsession
Microsoft l’avait promis pour l’été, voici la Technical Preview 4 pour Windows Server 2016. Cette version intègre notamment les conteneurs tant attendus. La Technical Preview disponible au format ISO et VHD pour les .