PowerShell v6 and PowerShell Direct

Not seen this reported anywhere so thought I post.

PowerShell v6 went to GA in January 2018. PowerShell Direct is a feature of Windows 10/Windows Server 2016. By accident I found that PowerShell v6 and PowerShell Direct work together.

PowerShell v6 is based on .NET core which is basically a subset of the full .NET CLR (that powers Windows PowerShell )

PowerShell Direct is a technology by which a PowerShell v5.1 session on a Windows 10/Windows Server 2016 Hyper-V host can establish a remoting session to a Windows 10/Windows Server 2016 virtual machine over the VM bus rather than using WSMAN.

By default PowerShell v6 can’t access the Hyper-V module but if you add the PowerShell v5.1 module path to the PowerShell v6 module path:

$env:PSModulePath = ‘C:\Windows\System32\WindowsPowerShell\v1.0\Modules\;’ + $env:PSModulePath

You can then create a credential

$cred = Get-Credential manticore\richard

This is required because you’re not relying on Kerberos to authenticate as you do in standard remoting within the domain.

You can then create your session:

$s = New-PSSession -VMName W10PRV01 -Credential $cred

And use it

Invoke-Command -Session $s -ScriptBlock {Get-Service}

The session has a ComputerType of VirtualMachine

PS>  $s | fl

ComputerType           : VirtualMachine
ComputerName           : W10PRV01
ContainerId            :
VMName                 : W10PRV01
VMId                   : 374d0569-3b22-441d-84dc-802aed67dea9
ConfigurationName      :
InstanceId             : c6e6b1c1-8ed5-409f-be4c-0a1262342cb7
Id                     : 1
Name                   : WinRM1
Availability           : Available
ApplicationPrivateData : {DebugMode, DebugStop, UnhandledBreakpointMode, PSVersionTable…}
Runspace               : System.Management.Automation.RemoteRunspace
State                  : Opened
IdleTimeout            : -1
OutputBufferingMode    :
DisconnectedOn         :
ExpiresOn              :

You can also enter the session

PS>  Enter-PSSession $s
[W10PRV01]: PS C:\Users\Richard.MANTICORE\Documents>

I’ve not tried all the Hyper-V cmdlets but the Get* cmdlets that I have tried all work.

Advertisements
This entry was posted in Hyper-V, PowerShell v6. Bookmark the permalink.

2 Responses to PowerShell v6 and PowerShell Direct

  1. Billy says:

    While this is good information. This situation reminds me of using Powershell in Orchestrator. Its not a great situation, I think they should have waited till more modules were ported over before making 6 GA.

    • You’re assuming that PowerShell v6 is a direct replacement/upgrade for V5.1. It ISN’T and this is what’s causing a lot of the confusion. PowerShell v6.0 should really be thought of as v1.0 of a new product

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s