Powershell PSCX写入Zip速度较慢



有人能帮我解决为什么此PSCX cmdlet"Write-Zip"如此缓慢的问题吗?DotNetZip库可以在大约20分钟内对相同的文件夹进行压缩,这需要1.5个小时。(DotNetZip库的问题是它被大文件卡住了,所以我切换到了PSCX,这是一个完美、酷的小进度条,它实际上也工作得很慢)。

这里有一些示例代码,如果您需要查看其他内容,请告诉我。

    $ElapsedTime = [System.Diagnostics.Stopwatch]::StartNew()
    Write-Host "Script Started at $(get-date)"
    Import-Module Pscx
    Import-Module BitsTransfer
    Write-Host "Just imported the BitsTransfer and Pscx modules"
    Write-Host "*** Starting backup portion of script ***"
    foreach($i in $appServers) {
            if (!(Test-Path -path \$ic$newDeploy)) {
                New-Item \$ic$newDeploy -type directory
                Write-Host "Just created newDeploy folder on $i"
            }
            if (!(Test-Path -path \$ic$newDeploybackup)) {
                New-Item \$ic$newDeploybackup -type directory
                Write-Host "Just created newDeploybackup folder on $i"
            }
            if(!(Test-Path \$ic$newDeployzipper.ps1)) {
                Start-BitsTransfer -Source \$appDeployServerc$newDeployzipper.ps1 -Destination \$ic$newDeploy
                Write-host "Just added zipper.ps1 to $i"
            }
    }
    foreach($i in $appServers) {
        $sessionForI = New-PSSession -computername $i
        Invoke-Command -Session $sessionForI -ArgumentList  $aosFolder, $i, $ElapsedTime -ScriptBlock {
            param ($aosFolder, $i, $ElapsedTime)
            Import-Module Pscx
            Write-Host "Just imported Pscx module for $i"
            if ((Test-Path C:\newDeploy\backup\$aosFolder.zip)) {
                Remove-Item C:\newDeploy\backup\$aosFolder.zip
                Write-Host "Just removed newDeploybackup$aosFolder.zip on $i"
            }
            Write-Host "Just started creating new ZIP file backup created on $i"
            Write-Host "   Elapsed Time: $($ElapsedTime.Elapsed.ToString())"
            cd "C:Program Files (x86)Folder$aosFolder"
            Get-ChildItem "C:Program Files (x86)Folder$aosFolder" -Recurse -Exclude *.e2e | Write-Zip -OutputPath "C:newDeploybackup$aosFolder.zip" -NoClobber -Level 1
            write-host "   Elapsed Time: $($ElapsedTime.Elapsed.ToString())"
            Write-Host "Just finished creating new ZIP file backup created on $i"
        }
        remove-PSSession -session $sessionForI
    }
    Write-Host "Just ran second foreach loop to ZIP all folders to backup on each server"
    foreach($i in $appServers) {
        if(!(Test-Path -path C:newDeploybackup$i)) {
            New-Item C:newDeploybackup$i -type directory
            Write-Host "Just created DEPLOY SERVER's newDeploybackup$i folder for backups"
        }
        Start-BitsTransfer -Source \$ic$newDeploybackup$aosFolder.zip -Destination C:newDeploybackup$i
        Write-Host "$i backup ZIP transferred to deploy server"
    }
    Write-Host "Just ran third foreach loop to move all ZIP files to the backup server for each remote server"
    foreach($i in $appServers) {
        Remove-Item \$ic$newDeploybackup$aosFolder.zip
        Write-Host "Just removed newDeploybackup$aosFolder.zip on $i"
    }
    Write-Host "Just ran forth foreach loop to delete all backup ZIP files to cleanup"
    $date = get-date -format "M-d-yyyy"
    Write-Zip -Path "C:newDeploybackup" -OutputPath "C:newDeploybackup$date APPbackup.zip" -NoClobber -Level 1
    Write-Host "Just ran final ZIP command to put all server's backups into one neat ZIP"
    foreach($i in $appServers) {
        if((Test-Path -path C:newDeploybackup$i)) {
            Remove-Item -Force -Recurse C:newDeploybackup$i
            Write-Host "Just removed DEPLOY SERVER's newDeploybackup$i folder"
        }
    }
    Write-Host "Just ran fifth foreach loop to delete each server's backup folder on the local server to cleanup"
    Write-Host "*** Finished with backup portion of script ***"
    Write-Host "*** Starting deploy preparation portion of script ***"

    Write-Host "*** Finished with deploy preparation portion of script ***"
    Write-Host "Script Ended at $(get-date)"

我建议您使用7zip命令行归档工具。它们非常敏捷,可以处理各种档案。

http://downloads.sourceforge.net/sevenzip/7za920.zip

以下是我的做法:

set-alias sz "$env:C:7za9207za.exe"
sz a -mx9 -tzip -r $FileName $SourceFolder

最新更新