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())
}
}
的[我要提取臨時使用PowerShell在一個給定的目錄中的所有.zip文件]可能的複製(http://stackoverflow.com/questions/28448202/i-want-to-extract -all-zip-files-in-a-given-directory-in-temp-using-powers) – BenH
我試圖在多個遠程服務器上解壓文件,但它只解壓出3個文件中的一個文件。我沒有收到任何錯誤,但不知怎的,它不正確。 –
我正在使用.NET Framework 4.5中包含的ExtractToDirectory方法作爲替代方法。 –