Powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-1098957%22%20slang%3D%22en-US%22%3EPowershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1098957%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20everyone%2C%3C%2FP%3E%3CP%3EI%20have%20been%20trying%20to%20create%20a%20PowerShell%20script%20to%20zip%20some%20files%20that%20are%20eating%20up%20my%20disk%20space%2C%20but%20the%20script%20keeps%20giving%20an%20error.%3C%2FP%3E%3CP%3EIf%20someone%20could%20help%20me%20to%20check%20this%20script%20I%20would%20quite%20appreciate%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFunction%20Zip%3CBR%20%2F%3E%7B%3CBR%20%2F%3EParam%3CBR%20%2F%3E(%3CBR%20%2F%3E%5Bstring%5D%24zipFile%3CBR%20%2F%3E%2C%3CBR%20%2F%3E%5Bstring%5B%5D%5D%24toBeZipped%3CBR%20%2F%3E)%3CBR%20%2F%3E%24CurDir%20%3D%20Get-Location%3CBR%20%2F%3ESet-Location%20%22C%3A%5CProgram%20Files%5C7-zip%5C%22%3CBR%20%2F%3E.%5C7z.exe%20A%20-tzip%20%24zipFile%20%24toBeZipped%3CBR%20%2F%3ESet-Location%20%24CurDir%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%24Now%20%3D%20Get-Date%3CBR%20%2F%3E%24Days%20%3D%20%221%22%3CBR%20%2F%3E%24TargetFolder%20%3D%20%22C%3A%5CProgram%20Files%5CPPContoso%5CContoDev%5CLogs%5C*.*%22%3CBR%20%2F%3E%24LastWrite%20%3D%20%24Now.AddDays(-1)%3CBR%20%2F%3E%24Files%20%3D%20Get-Childitem%20%24TargetFolder%20-Recurse%20%7C%20Where%20%7B%24_.LastWriteTime%20-le%20%22%24LastWrite%22%7D%3CBR%20%2F%3E%24Files%3CBR%20%2F%3EZip%20C%3A%5CProgram%20Files%5CPPContoso%5CContoDev%5CLogs%5C*.log%20%24Files%3CBR%20%2F%3E%23If(Test-Path%20C%3A%5CProgram%20Files%5CPPContoso%5CContoDev%5CLogs%5CLogs.zip)%3CBR%20%2F%3E%23%7B%3CBR%20%2F%3E%23%20Remove-Item%20%24files%3CBR%20%2F%3E%23%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20the%20above%20keeps%20giving%20error.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
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
{
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.

0 Replies