Hi!
I currently try to move some old cmd/batch scripts to PS, finally! Currently I have a script that finds all .bak-files and creates a 7ziped file along with it if it does not exist.
My current script looks like this:
for /R "E:\Backup" %%f in (*.bak) do ( echo %%f if not exist "%%f.7z" ( 7Z a "%%f.7z" "%%f" ) )
So I’m trying to rewrite in PS.
This will give me the list of all .back-files, but how do I add .7z to the filename and test it it does exist (Test-Path):
$path = "E:\Backup" Get-ChildItem -Path $path -Recurse -Filter *.bak | Test-Path -Path %{$_.FullName} # Add .7z here?
And in the next step I’ll run the command to create the 7z-file:
7z.exe a "file.bak.7z" "file.bak"
Should I store all found files in an array and iterate the array, or should I use the ‘|’ to chain the commands?
Thanks for advice!