Powershell Scripting - Zipping, Moving BAK files to a new folder named for the date of BAK file creation

Firstly, Hello and apologies for the stupidly long title...

Secondly, I hope someone out there can help with what should be a simple task that has annoyed me for the past 4days, I will elaborate;

  1. I have 4 x BAK file that are created between 22:30 and 23:00hrs each night.
  2. Each BAK file is named differently and we append the date in format "yyyy_MM_dd".
  3. I need to 7z each BAK file into separate archives and move them to a new directory either named for the date they where created or the appended date of the file but keep the format "yyyy_MM_dd". (Both will be the same obviously but the code will be different, so whichever is easiest)

I believe I have the separate lines for some of the script I need...

  • For Creating the 7z

dir *.bak | ForEach-Object { & "C:\Program Files\7-Zip\7z.exe" a -t7z -mx3 ($.Name+".7z") $.Name }

  • For Creating the folder

$Folder = New-Item -ItemType Directory -Path "DRIVE2:\Folder1\Folder2\$((Get-Date).ToString('yyyy-MM-dd'))"

  • For Moving the files

Get-ChildItem 'DRIVE1:\Folder1\Folder2\*.7z' | Copy-Item -Destination $Folder

Can someone point out where I am being a complete nugget with this?

Thanks in advance



If the files to copy are in DRIVE1:\Folder1\Folder2, then you are missing a slash between the folder and the wildcard.

Get-ChildItem 'DRIVE1:\Folder1\Folder2\*.7z' | Copy-Item -Destination $Folder

Need Your Help

User Group and Role Management in .NET with Active Directory

.net asp.net security active-directory

I'm currently researching methods for storing user roles and permissions for .NET based projects. Some of these projects are web based, some are not. I'm currently struggling to find the best metho...