Jump to content

Script zum Kopieren von Dateien inkl. Quellpfad


Recommended Posts

Hallo alle zusammen, ich habe mir ein script erstellt, welches nach Dateien die in einem Zeitraum geändert wurden sucht und diese dann kopieret.

Der Auszug sieht wie follgt aus.

$Date = Get-Date
$Days = 1
$DateBeforeXDays = (Get-Date).AddDays(-$Days)

Get-childitem -Path "C:\123\*" -Include "*.*" -recurse | Where-Object { $_.CreationTime -ge $DateBeforeXDays -and $_.CreationTime -le $Date } | Copy-Item -Destination "O:\abc" -recurse -Verbose 4> $Logdatei

 

Mein Problem ist das, wenn z.b. eine Datei in "C:\123\456\789\000\" liegt, die kopiert werden soll, der Pfad nicht auf der Zielseite erstellt wird. Gibt es dafür eine Möglichkeit, dass die Ordner auf der Zielseite erstellt werden, so wie es auf der Quellseite vorliegt?

Link to comment
vor 36 Minuten schrieb Mario-HS:

Gibt es dafür eine Möglichkeit, dass die Ordner auf der Zielseite erstellt werden, so wie es auf der Quellseite vorliegt?

Ja. Dafür müsstest Du den relativen Pfad-Anteil der Datei extrahieren und diesen dann zum Ziel-Basis-Pfad "addieren". Ich würd aber auch eher robocopy bemühen - das ist für solche Einsatzzwecke gemacht. ;-)   ... und da kann man übrigens mit /maxage oder /minage  auch Dateien auswählen die ein bestimmtes Maximal- oder Minimal-Alter haben.

Link to comment
Posted (edited)
Zitat

Magst Du Deine Lösung nicht mit der Welt teilen? Vielleicht hilft es mal jemand anderem, der das gleiche oder ein ähnliches Problem hat.

Klar, das ganze script sieht wie folgt aus.

 

$Date = Get-Date -Format "MM/dd/yyyy"
$Date_2 = Get-Date -Format "dddd dd/MM/yyyy"

$write_disk = Get-Disk | Where-Object IsOffline -Eq $True
Get-Disk | Where-Object IsOffline -Eq $True | set-disk -IsOffline $false

$unlock_bitlocker = ConvertTo-SecureString 'abcdefghijklmnopqrstuvwxyz' -AsPlainText -Force
Get-BitLockerVolume
$Laufwerk = Get-BitLockerVolume | Where ProtectionStatus -eq Unknown
$Ext_hdd = $Laufwerk.MountPoint

Unlock-BitLocker -MountPoint $Ext_hdd -Password $unlock_bitlocker
set-Disk $write_disk.Number -isReadOnly $false

$date= get-date -format d

New-Item -Path "$Ext_hdd\$Date_2\0011223344" -ItemType Directory
New-Item -Path "$Ext_hdd\$Date_2\5566778899" -ItemType Directory
$Destination_0011223344 = "$Ext_hdd\$Date_2\0011223344"
$Destination_5566778899 = "$Ext_hdd\$Date_2\5566778899"

New-PSDrive -Name "M" -PSProvider "FileSystem" -Persist -Root "\\127.0.0.1\0011223344"
New-PSDrive -Name "N" -PSProvider "FileSystem" -Persist -Root "\\127.0.0.1\5566778899"

Robocopy M:\ $Destination_0011223344 /MAXLAD:1 -S
Robocopy N:\ $Destination_5566778899 /MAXLAD:1 -S

sleep 2
Get-PSDrive -name M | Remove-PSDrive -force
Get-PSDrive -name N | Remove-PSDrive -force

Lock-BitLocker -MountPoint $Ext_hdd -ForceDismount

$offline = get-wmiobject -class win32_logicaldisk | Where DeviceID -Like $Ext_hdd
get-disk | where FriendlyName -Like "LAUFWERKBEZEICHNUNG" | set-disk -IsOffline $true

 

Edited by Mario-HS
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...