Zipar aquivos - PowerShell


Pergunta:
Preciso criar uma rotina em powershell para zipar uma pasta em um caminho específico.

Resposta:
$mes= Get-Date -Format "MMdyyyy"
$SourceFolder    = "C:\XP\XP.Automate.CMTIMS.TH\temp\$mes"
$DestinationFile = "\\fsxp\internacional\CM TIMS Timber Hill\2015"
$Compression     = "Optimal"  # Optimal, Fastest, NoCompression

Zip-Directory -DestinationFileName $DestinationFile `
    -SourceDirectory $SourceFolder `
    -CompressionLevel $Compression ` #Optional parameter
    -IncludeParentDir #Optional parameter

function Zip-Directory {
    Param(
      [Parameter(Mandatory=$True)][string]$DestinationFileName,
      [Parameter(Mandatory=$True)][string]$SourceDirectory,
      [Parameter(Mandatory=$False)][string]$CompressionLevel = "Optimal",
      [Parameter(Mandatory=$False)][switch]$IncludeParentDir
    )
    Add-Type -AssemblyName System.IO.Compression.FileSystem
    $CompressionLevel    = [System.IO.Compression.CompressionLevel]::$CompressionLevel
    [System.IO.Compression.ZipFile]::CreateFromDirectory($SourceDirectory, $DestinationFileName, $CompressionLevel, $IncludeParentDir)




Tecnologia do Blogger.