Running a command on each directory in a list using PowerShell
You don't need to set the location, you just just provide paths to 7z.exe. Also, 7zip does not compress to Rar, only decompress.
$dir = dir d:\directory | ?{$_.PSISContainer}
foreach ($d in $dir){
$name = Join-Path -Path $d.FullName -ChildPath ($d.Name + ".7z")
$path = Join-Path -Path $d.FullName -ChildPath "*"
& "C:\Program Files\7-Zip\7z.exe" a -t7z $name $path
}
If you don't want to remove the logs after zipping it, comment out the 3rd line
function zip-log {
Compress-Archive *.log Logs.zip
Get-Item *.log | Remove-Item -Force
}
$dir = Get-ChildItem d:\directory| ? {$_.PSIsContainer}
$dir | ForEach-Object {Set-Location $_.FullName; zip-log}