2017-01-16 5 views
0

Compress-Archive을 어떻게 하위 폴더 구조 만 압축합니까? 이제 스크립트 자체가 .zip에 포함됩니다. 아니면 그것을 필터링 할 수 있습니까?스크립트에 지정된 압축 아카이브에 스크립트 자체가 포함되어 있습니다.

는 다음과 내가 가진 코드는대로 :

if (!($PSScriptRoot)) { Split-Path $MyInvocation.MyCommand.Path -Parent } 
$destination = Split-Path $MyInvocation.MyCommand.Path -Parent 
$source = (Get-ChildItem $PSScriptRoot) 
$date = Get-Date -UFormat "%Y-%m-%d" 
$zipfile = $destination + "\createdOn" + $date + ".zip" 

#Check if file exists 
if ([System.IO.File]::Exists($zipfile)) 
{ 
    Clear-Host 
    Write-Host "File created: " $zipfile 
    Compress-Archive -DestinationPath $zipfile -Force -Path $source -CompressionLevel Optimal 
} 
else 
{ 
    Clear-Host 
    Write-Host "File created: " $zipfile 
    Compress-Archive -DestinationPath $zipfile -Force -Path $source -CompressionLevel Optimal 
} 
+0

을 어떻게 PowerShell을 v2를에'압축-Archive'을 사용할 수있을 것으로 예상합니까? –

답변

1

시도 :

$source = (Get-ChildItem $PSScriptRoot -exclude $MyInvocation.MyCommand) 
1

당신이 $PSScriptRoot (스크립트의 상위 폴더)의 하위 항목에 $source 설정하면 다음 생성 해당 항목의 보관 파일은 왜 결과 보관 파일 이 아니고에 해당 폴더의 하위 항목 중 하나 인 스크립트가 포함되어 있습니까?

아카이브에있는 그것의 포함 피하기 위해 $source에서 스크립트 파일을 제거

$source = Get-ChildItem $PSScriptRoot | 
      Where-Object { $_.FullName -ne $PSCommandPath }