Since I couldn’t install Compress-Archive on PS4, I solved my question by using the method CopyHere
, as follows:
$fileAge = 180
[byte[]] $emptyZipBytes = @(80,75,5,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
$logFiles = Get-ChildItem C:\logs | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-$fileAge)}
$logFilePaths = @()
foreach($logFile in $logFiles) {
$logFilePaths += $logFile.FullName
}
$zipFile = C:\Archive\logs.zip
If (![io.file]::Exists($zipFile)) {
[io.file]::WriteAllBytes($zipFile,$emptyZipBytes)
}
If ($logFilePaths.Count -gt 0) {
foreach ($fPath in $logFilePaths) {
(New-Object -Com Shell.Application).NameSpace($zipFile).CopyHere($fPath, 0x14)
Get-Process powershell -ea 0 | Where-Object MainWindowTile -match "(\d{1-3} concluído)|(Comprimindo...)" | Wait-Process
}
Remove-Item $logFilePaths
}