Tinus EngOps Wiki

Logo

OpsaC - Operating as PowerShell code

Links

Home

IT-Wiki

PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View my Codeberg Page

View my Photo Website

Copy-VMFile

published: September 12, 2017 author: Tinu tags: Hyper-V categories: PowerShell - Virtualisierung


Files vom physischen (HyperV) Host auf VMs kopieren

Voraussetzungen: Im Hyper-V-Manager unter Integrationsdienste die Gastdienste aktivieren.

Enable-VMIntegrationService -VMName "*" -Name "Guest Service Interface"

This example copies the file “C:\Daten\Bginfo.exe” from the host operating system into the guest operating system of the virtual machine “W2K16RC-SRV01”. It will create the directory “C:\Work” inside the guest operating system if it does not exist already.

$vmname = 'W2K16RC-SRV01'
$source = 'C:\Daten\Bginfo.exe'
$target = 'C:\Work\Bginfo.exe'
Copy-VMFile $vmname -SourcePath $source -DestinationPath $target -CreateFullPath -FileSource Host

This example copies the content from “C:\Daten\Templates” from the host operating system into the guest operating system of the virtual machine “W2K16RC-SRV01”. It will create the directory “C:\Daten\Templates” inside the guest operating system if it does not exist already.

$vmname  = 'W2K16RC-SRV01'
$sources = Get-ChildItem -Path 'C:\Daten\Templates' -Recurse

foreach($item in $sources){
    Copy-VMFile -FileSource Host -VMName $vmname -SourcePath "$($item.FullName)" -DestinationPath "$($item.FullName)" -CreateFullPath -Force
}

← Previous Post ◇ [ Top ] ◇ Copyright © 2024 by tinuwalther ◇ [ Blog ] ◇ Next Post →