112timo
Goto Top

Dateien trotz Verwendung kopieren

Hallo

ich möchte Dateien mit der PowerShell kopieren. Diese gibt mir aber zurück, dass die Dateien gerade in Verwendung sind nicht kopiert werden können.

Kann mir jemand sagen, wie ich die Dateien trotz Verwendung kopieren kann?
Bitte keine extra Tools, das soll alles mit Powershell funktionieren.

Gruß Timo
unbenannt

Content-Key: 310985

Url: https://administrator.de/contentid/310985

Printed on: April 24, 2024 at 12:04 o'clock

Mitglied: 129813
129813 Jul 27, 2016 updated at 08:31:30 (UTC)
Goto Top
Make a shadow copy mount the shadow copy to a folder and copy it from there, or use wbadmin to backup the system state.

Regards
Member: colinardo
colinardo Jul 27, 2016 updated at 09:06:30 (UTC)
Goto Top
Hallo Timo,
wie @129813 schon richtig angedeutet hat, ist es eine Möglichkeit eine Schattenkopie zu erstellen und zu mounten um beliebige Dateien problemlos herauszukopieren:
# path where the shadow copy will be mounted temporarily
$mount_path = "$env:Temp\MountPointShadowCopy"  
# function to create softlink
function New-Softlink {
    param
    (
        [Parameter(Mandatory=$true)]$symlinkpath,
        [Parameter(Mandatory=$true)]$targetpath,
        [Parameter()][switch]$dir
    )
    $code = '  
            [DllImport("Kernel32.dll")]  
            public static extern bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, int dwFlags);
    '  
    Add-Type -MemberDefinition $code -Name Links -Namespace Utils 
    if ($dir.IsPresent){$type = 1}else{$type= 0}
    [Utils.Links]::CreateSymbolicLink($symlinkpath,$targetpath,$type)
} 

# create shadow copy from drive c:
$result = ([WMICLASS]"root\cimv2:win32_shadowcopy").Create("C:\", "ClientAccessible")  
# get global root path of shadow copy
$path = gwmi win32_ShadowCopy | ?{$_.ID -eq $result.ShadowID} | select -Expand DeviceObject
# mount shadow copy to a fs path via softlink
New-Softlink $mount_path "$path\" -dir | out-null  
# copy path from shadow copy to a dir named E:\target
copy-item "$mount_path\Windows\system32\config" -Recurse -Destination "E:\target" -Force  
# remove softlink
cmd /c rd "$mount_path"  
Eine System-State-Sicherung mit wbadmin sichert dir dir Registry-Hives aber ebenfalls.

Grüße Uwe