Forum Discussion

tonnybabs's avatar
tonnybabs
Copper Contributor
Jan 09, 2020

Powershell

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
{
Param
(
[string]$zipFile
,
[string[]]$toBeZipped
)
$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"}
$Files
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.

No RepliesBe the first to reply

Share

Resources