[英]Copy files and put into zip file from batch file or windows command line
如何從本地網絡中的另一台計算機復制文件並將其另存為zip文件在本地計算機中? 有沒有辦法使用xcopy,robocopy或類似程序直接壓縮文件?
從Powershell角度回答:
在V5之前,有幾種使用Powershell壓縮文件的實現,在V5中有一個cmdlet compress-archive
。
在這里,您可以找到指向您的問題的類似鏈接(本地來源,unc dest),但在其他方面應該相同。
如果兩台計算機上都安裝了powershell,則只需執行以下代碼即可。
Legit credentials = new credentials.
$s = New-PSSession -ComputerName RemotePc -Credential LegitCredentials
Invoke-Command -Session $s -ScriptBlock
{
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory($SourcePath,$destinationPath)
Move-item from $destinationPath to sharedPath
Move-item from sharedpath to localpath
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.