Mario-HS 5 Posted March 16 Report Share Posted March 16 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? Quote Link to comment
NilsK 2,225 Posted March 16 Report Share Posted March 16 Moin, schau dir mal robocopy in einem CMD-Fenster an. Gruß, Nils Quote Link to comment
BOfH_666 442 Posted March 16 Report Share Posted March 16 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. Quote Link to comment
daabm 837 Posted March 16 Report Share Posted March 16 Noch einer, der sagt "nimm Robocopy" - Powershell ist für so was "auf lange Sicht" um Welten zu langsam. Wenn Du nicht mit [System.IO] arbeiten willst. Quote Link to comment
Mario-HS 5 Posted March 21 Author Report Share Posted March 21 Hallo miteinander, danke für die Tipps habe es hinbekommen. Etwas b***d ist das Robocopy keine PS-Objekte verarbeiten kann aber immer noch besser, als das es gar nicht geht. Quote Link to comment
BOfH_666 442 Posted March 21 Report Share Posted March 21 vor 2 Minuten schrieb Mario-HS: habe es hinbekommen Magst Du Deine Lösung nicht mit der Welt teilen? Vielleicht hilft es mal jemand anderem, der das gleiche oder ein ähnliches Problem hat. Quote Link to comment
Mario-HS 5 Posted March 21 Author Report Share Posted March 21 (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 March 21 by Mario-HS Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.