How to Copy Files from a Hyper-V VM to the Host

Sometimes you might need to copy files from a Hyper-V Virtual Machine or Guest to the Hyper-V Host.

PowerShell can easily help you with that. Just use the -VMName parameter with the New-PSSession cmdlet on the Hyper-V Host to create a new session to the Hyper-V VM and store it in a variable. Provide credentials for the VM if needed.

1
$session = New-PSSession -VMName "vmname" -Credential (Get-Credential)

Then use the stored session with the -FromSession parameter with the Copy-Item cmdlet and copy your file(s) from the VM to the Host.

1
Copy-Item -FromSession $session -Path "C:\path_on_vm\*" -Destination "C:\path_on_host\"

Using -ToSession gives you a solutions to copy files the other way round: from the Host to the VM.

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.