PowerShell Direct example

Last week I mentioned PowerShell and how you can create a PowerShell Remoting session to a Virtual Machine that’s running on Hyper-V

Here’s an example of it in use:

$cred = Get-Credential W16TP5TGT01\Administrator
$s = New-PSSession -VMName W16TP5TGT01 -Credential $cred

Create the credential for the VM and then create the remoting session. I prefer to use the VM name rather than the GUID.

Once you’ve established the session you can use it. In this case I’m using another PowerShell 5.o innovation to copy a file across the remote session:

Copy-Item -Path ‘C:\Source\Windows 2016 TP5\Cumulative Update for Windows Server 2016 Technical Preview 5 (KB3163016)\AMD64-all-windows10.0-kb3163016-x64_83d6e9bca94a64a5d9be3d81cdb182e540285848.msu’ -Destination c:\source -ToSession $s

Clean up as usual:

Remove-PSSession -Session $s

PowerShell Direct is another useful addition to the remoting toolbox. It’ll be especially useful in non-domain remoting situations.

This entry was posted in PowerShell v5, Virtualisation, Windows Server 2016. Bookmark the permalink.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s