Compress-Archive -Path System.String[] Parâmetro de data

Francisco Lucas Nogueira Teixeira 26 Reputation points
2022-10-19T19:54:36.747+00:00

Olá, estou desenvolvendo um script no Powershell que compacta arquivos de uma só extensão, no caso é a .xml, eu também preciso filtrar por data, para ele compactar somente os arquivos de um mês atrás, e é este último objetivo que me falta.

O código está assim:

Compress-Archive -Path $currentDrive\TOTVSPDV\PROTHEUS_DATA\AUTOCOM\*.xml -CompressionLevel Optimal -DestinationPath $currentDrive\TOTVSPDV\PROTHEUS_DATA\$Data.zip

Sou novo no Powershell então agradeço se houver algum feedback.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,427 questions
0 comments No comments
{count} vote

Accepted answer
  1. Rich Matheisen 45,416 Reputation points
    2022-10-19T20:11:44.71+00:00

    I think this is what you're looking for:

    $MonthAgo = (Get-Date).Date.AddMonths(-1)  
    $Files =    Get-ChildItem -Path $currentDrive\TOTVSPDV\PROTHEUS_DATA\AUTOCOM\*.xml |  
                    Where-Object LastWriteTime -gt $MonthAgo |  
                        Select-Object -Expand FullName  
    Compress-Archive -Path $Files -CompressionLevel Optimal -DestinationPath $currentDrive\TOTVSPDV\PROTHEUS_DATA\$Data.zip  
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful