Introduction: PowerShell Direct

PowerShell Direct is a new feature to Windows Management Framework version 5 that allows for Windows hosts to run PowerShell commands against a Hyper-V guest. Think of this as PowerShell Remoting without the need to enable remoting on the guest operating system. Your guest doesn’t have to configure the firewall to allow for remoting. You don’t even need a network card.

Instead of the Hyper-V rolling out their own PowerShell Direct remoting tool Microsoft opted to integrate PowerShell Direct into the PSSession cmdlets. Notice when you run Get-Command against Enter-PSSession you get eight different parameter sets.

Note: This only works on Windows 10/Server vNext hosts to Windows 10/Server vNext guests.

PS:> Get-Command -Name Enter-PSSession -Syntax

Enter-PSSession [-ComputerName] <string> [-EnableNetworkAccess] [-Credential <pscredential>] [-ConfigurationName <string>] [-Port <int>] [-UseSSL] [-ApplicationName <string>] [-SessionOption <PSSessionOption>] [-Authentication <AuthenticationMechanism>] [-CertificateThumbprint <string>] [<CommonParameters>]

Enter-PSSession [[-Session] <PSSession>] [<CommonParameters>]

Enter-PSSession [[-ConnectionUri] <uri>] [-EnableNetworkAccess] [-Credential <pscredential>] [-ConfigurationName <string>] [-AllowRedirection] [-SessionOption <PSSessionOption>] [-Authentication <AuthenticationMechanism>] [-CertificateThumbprint <string>] [<CommonParameters>]

Enter-PSSession [-InstanceId <guid>] [<CommonParameters>]

Enter-PSSession [[-Id] <int>] [<CommonParameters>]

Enter-PSSession [-Name <string>] [<CommonParameters>]

Enter-PSSession [-VMId] <guid> [-Credential] <pscredential> [-ConfigurationName <string>] [<CommonParameters>]

Enter-PSSession [-VMName] <string> [-Credential] <pscredential> [-ConfigurationName <string>] [<CommonParameters>]

Enter-PSSession [-ContainerId] <string> [-ConfigurationName <string>] [-RunAsAdministrator] [<CommonParameters>]

The last two Enter-PSSession -VMGuid and Enter-PSSession -VMName are new in Windows 10. They allow you to enter a remote session from a Hyper-V host. When running against a Hyper-V guest you need to provide PSCredentials in order to authenticate.

As of the Windows 10 Build 10130 there are only three commands that have a -VMName or -VMGuid parameter name.

PS:> Get-Command -ParameterName VMGUID,VMName

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Enter-PSSession                                    3.0.0.0    Microsoft.PowerShell.Core
Cmdlet          Get-PSSession                                      3.0.0.0    Microsoft.PowerShell.Core
Cmdlet          Invoke-Command                                     3.0.0.0    Microsoft.PowerShell.Core
Cmdlet          New-PSSession                                      3.0.0.0    Microsoft.PowerShell.Core
Cmdlet          Remove-PSSession                                   3.0.0.0    Microsoft.PowerShell.Core

To run Get-Process against a VM.

$Credential = Get-Credential 
Invoke-Command -VMName "Windows 10" -Credential $Credential -ScriptBlock { Get-Process }

The possibilities are endless when you can run jobs, invoke commands, and work interactively with a guest virtual machine. It is plain to see why a technology like this is important. Begin able to manage your virtual machines through a dedicated and secure management interface. Look for more announcements from the Hyper-V blog.