Add files of one type to one zip file and clean up using PowerShell

后端 未结 2 1756
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-24 07:21

How can I create a PowerShell script to get all files of type .BAK and add them to a ZIP file (can I have my PowerShell script take a parameter when called to control the name o

2条回答
  •  攒了一身酷
    2021-01-24 07:54

    If you're using PowerShell v5 then you can use the Compress-Archive function instead of using 7zip:

    $filePath = "C:\SQLBackups"
    $ZipName = "v4.14.4_backups.zip"
    
    $BakFiles = Get-ChildItem -Recurse -Path $filePath -Include *.bak
    
    $BakFiles | Compress-Archive -DestinationPath "$filePath\$ZipName"
    $BakFiles | Remove-Item -Force
    

提交回复
热议问题