PowerShell Direct lets you remotely connect to a Virtual Machine running on a Hyper-V host, without any network connection inside the Virtual Machine. PowerShell Direct uses the Hyper-V VMBus to connect inside the Virtual Machine. This feature is convenient if you need it for automation and configuration for Virtual Machines or if you, for example, messed up network configuration inside the virtual machine, and you don’t have console access.
Right now, there are two ways to use PowerShell Direct:
You can open a new interactive PowerShell Direct Session:
Enter-PSSession -VMName "VM01" -Credential (Get-Credential)
You can use Invoke-Command to send script blocks to your Hyper-V Virtual Machines.
Invoke-Command -VMName "VM01" -Credential (Get-Credential) -ScriptBlock { Get-Process }
You can also create a PowerShell Direct session and use the Copy-Item -ToSession cmdlet to copy files to or from the VM.
$s = New-PSSession -VMName "VM01" -Credential (Get-Credential) Copy-Item C:\Files C:\Targetfiles -ToSession $s
Remember it, this is not the same as PowerShell Remoting, even if it uses the same cmdlets. With that, not everything is working using PowerShell Direct, for some scenarios, PowerShell Remoting works differently. If you want to do this with Linux virtual machines, there is a tool called hvc.exe, which allows you to do the same.
If you want to know more about PowerShell Direct, check out the Microsoft Docs pages.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.