Introduction: PowerShell Direct

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.

[code lang=powershell]
get-command -Name Enter-PSSession -Syntax
[/code]

[code lang=text]
Enter-PSSession [-ComputerName] [-EnableNetworkAccess] [-Credential ] [-Port ] [-UseSSL] [-ConfigurationName ] [-ApplicationName ] [-SessionOption ] [-Authentication ] [-CertificateThumbprint ] [] Enter-PSSession [[-Session] ] [] Enter-PSSession [[-ConnectionUri] ] [-EnableNetworkAccess] [-Credential ] [-ConfigurationName ] [-AllowRedirection] [-SessionOption ] [-Authentication ] [-CertificateThumbprint ] [] Enter-PSSession [-InstanceId ] [] Enter-PSSession [[-Id] ] [] Enter-PSSession [-Name ] [] Enter-PSSession [-VMGuid] [-Credential] [] Enter-PSSession [-VMName] [-Credential] []
[/code]

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.

[code lang=powershell]
get-command -ParameterName VMGUID,VMName
[/code]

[code lang=text]
CommandType Name Version Source ———– —- ——- —— Cmdlet Enter-PSSession 3.0.0.0 Microsoft.PowerShell.Core Cmdlet Invoke-Command 3.0.0.0 Microsoft.PowerShell.Core Cmdlet Start-Job 3.0.0.0 Microsoft.PowerShell.Core
[/code]

To run Get-Process against a VM.

[code lang=powershell]
$Credential = Get-Credential Invoke-Command -VMName "Windows 10" -Credential $Credential -ScriptBlock { Get-Process }
[/code]

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.