header image

PowerShell Direct example

Posted by: | July 8, 2016 Comments Off on 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.

under: PowerShell v5, Virtualization, Windows Server 2016

Comments are closed.

Categories