PowerShell

PowerShell: Copy File to multiple (all) Hyper-V VMs

In this post, I’ll show you how to copy one or more files to all VMs in Hyper-V. I would say: Let’s get started.

Prerequisites

To copy files, guest services must be enabled on all VMs. The guest services are part of the integration services. By default, they are not enabled!

To enable Guest Services on all Hyper-V VMs run the code below.

Get-VM | Enable-VMIntegrationService -Name 'Guest Service Interface'

Then the verification.

Get-VM | Get-VMIntegrationService

Action: Copy one file to all VMs

Now we are ready to copy a file to all VMs. The file will be copied from the user home folder to the user home folder on the VM. Let’s go.

New-Item $home -ItemType File -Name datei1.txt -Value 'Hello World' -Force

$vm = (Get-VM).Name
foreach ($v in $vm) {
    Copy-VMFile $v -SourcePath $home\datei1.txt -DestinationPath $home\datei1.txt -CreateFullPath -FileSource Host -Verbose
}

Mission accomplished.

1 reply »

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.