Occasional Contributor

Hello everyone,

I have been trying to create a PowerShell script to zip some files that are eating up my disk space, but the script keeps giving an error.

If someone could help me to check this script I would quite appreciate this.



Function Zip
$CurDir = Get-Location
Set-Location "C:\Program Files\7-zip\"
.\7z.exe A -tzip $zipFile $toBeZipped
Set-Location $CurDir
$Now = Get-Date
$Days = "1"
$TargetFolder = "C:\Program Files\PPContoso\ContoDev\Logs\*.*"
$LastWrite = $Now.AddDays(-1)
$Files = Get-Childitem $TargetFolder -Recurse | Where {$_.LastWriteTime -le "$LastWrite"}
Zip C:\Program Files\PPContoso\ContoDev\Logs\*.log $Files
#If(Test-Path C:\Program Files\PPContoso\ContoDev\Logs\Logs.zip)
# Remove-Item $files


But the above keeps giving error.

0 Replies