0
현재 간단한 PowerShell 스크립트를 작성하고 있습니다. 기본적으로 메모장에서 서버 목록을 가져 와서 각 서버에서 .zip 파일의 압축을 풀고 새 폴더에 압축을 풀어야합니다.Powershell을 통해 여러 원격 서버에서 파일 압축을 풉니 다.
그러나이 스크립트는 zip 파일 아래의 모든 파일을 추출하지 않습니다. 그것은 하나의 파일 만 추출 할 것이고 foreach 루프가 제대로 작동하지 않는 이유가 확실하지 않습니다.
이 문제에 대해 알려주십시오. 감사.
$servers = Get-Content "C:\tmp\script\new_unzip\servers.txt"
$Date = ((Get-Date).ToString('dd-MM-yyyy_HH-mm-ss'))
foreach ($server in $servers) {
$shell = new-object -com shell.application
$target_path = "\\$server\c$\Temp\FFPLUS_Temp"
$location = $shell.namespace($target_path)
$ZipFiles = Get-ChildItem -Path $target_path -Filter *.zip
$ZipFiles | Unblock-File
foreach ($ZipFile in $ZipFiles) {
$ZipFile.fullname | out-default
$NewLocation = "\\$server\c$\Temp\FFPLUS_Temp\$Date"
New-Item $NewLocation -type Directory -Force -ErrorAction SilentlyContinue
Move-Item $ZipFile.fullname $NewLocation -Force -ErrorAction SilentlyContinue
$NewZipFile = Get-ChildItem $NewLocation *.zip
$NewLocation = $shell.namespace($NewLocation)
$ZipFolder = $shell.namespace($NewZipFile.fullname)
$NewLocation.copyhere($ZipFolder.items())
}
}
[I가 임시 사용 PowerShell에서 특정 디렉토리에있는 모든 .ZIP 파일을 추출 할]의 사용 가능한 복제 (http://stackoverflow.com/questions/28448202/i-want-to-extract -all-zip-files-in-a-given-directory-in-temp-using-powershell) – BenH
여러 원격 서버에서 파일의 압축을 풀려고하지만 파일 3 개 중 하나의 파일 만 압축을 풉니 다. 나는 어떤 오류도받지 못했지만 어떻게 든 그것이 제대로되지 않습니다. –
다른 방법으로 .NET Framework 4.5에 포함 된 ExtractToDirectory 메서드를 사용하고 있습니다. –