compression - Powershell Scripting - Zipping, Moving BAK files to a new folder named for the date of BAK file creation -
firstly, hello , apologies stupidly long title...
secondly, hope out there can should simple task has annoyed me past 4days, elaborate;
- i have 4 x bak file created between 22:30 , 23:00hrs each night.
- each bak file named differently , append date in format "yyyy_mm_dd".
- i need 7z each bak file separate archives , move them new directory either named date created or appended date of file keep format "yyyy_mm_dd". (both same code different, whichever easiest)
i believe have separate lines of script need...
- for creating 7z
dir *.bak | foreach-object { & "c:\program files\7-zip\7z.exe" -t7z -mx3 ($.name+".7z") $.name }
- for creating folder
$folder = new-item -itemtype directory -path "drive2:\folder1\folder2\$((get-date).tostring('yyyy-mm-dd'))"
- for moving files
get-childitem 'drive1:\folder1\folder2\*.7z' | copy-item -destination $folder
can point out being complete nugget this?
thanks in advance
robd
if files copy in drive1:\folder1\folder2, missing slash between folder , wildcard.
get-childitem 'drive1:\folder1\folder2\*.7z' | copy-item -destination $folder
Comments
Post a Comment