在远程PC上调用时无法解压缩文件夹

时间:2019-03-27 14:56:33

标签: powershell extract invoke unzip scriptblock

我正在尝试将共享驱动器上的文件夹解压缩到远程PC上C:\的根目录下,但一直出现错误,我该如何纠正此Powershell?

$Computers = "LN-T48-PF11BL57"
Invoke-Command -Computername $Computers -ScriptBlock {
         Expand-Archive -LiteralPath '\\LNAPPS\APPS\Adobe iManage Fix\Program Files (x86).zip' -DestinationPath C:\ -Force } -Verbose

Write-Host "Enter to Exit"

这将返回以下错误:

A positional parameter cannot be found that accepts argument '\\LNAPPS\APPS\Adobe iManage Fix\Program Files (x86).zip'.  
    + CategoryInfo          : InvalidArgument: (:) [Expand-Archive], ParameterBindingException  
    + FullyQualifiedErrorId : PositionalParameterNotFound,Expand-Archive  
    + PSComputerName        : LN-T48-PF11BL57

1 个答案:

答案 0 :(得分:0)

这里有几件事:

  1. 请记住Windows禁止在根c:中放入内容。
  2. 因此,我们是否假设\ LNApps是服务器名称而\ APPS是服务器名称 该服务器上配置了文件夹共享?
  3. 最后,除非该服务器运行的是PowerShell v5,否则 Expand-Archive cmdlet不存在。

因此...

  

:InvalidArgument:(:) [Expand-Archive],ParameterBindingException

(Get-CimInstance -ClassName CIM_OperatingSystem).Caption
Microsoft Windows Server 2012 R2 Standard

$PSVersionTable


Name                           Value
----                           -----
PSVersion                      4.0
WSManStackVersion              3.0
SerializationVersion           1.1.0.1
CLRVersion                     4.0.30319.42000
BuildVersion                   6.3.9600.19170
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.2



Get-Command -Name '*Expand-archive*'

# No results



(Get-CimInstance -ClassName CIM_OperatingSystem).Caption

Microsoft Windows 10 Pro

$PSVersionTable


Name                           Value
----                           -----
PSVersion                      5.1.17763.316
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.17763.316} 
BuildVersion                   10.0.17763.316
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1




Get-Command -Name '*Expand-archive*'


CommandType     Name               Version    Source
-----------     ----               -------    ------
Function        Expand-Archive     1.0.1.0    Microsoft.PowerShell.Archive

如果该cmdlet不存在,则需要使用.Net命名空间System.IO.Compression.FileSystem来处理此用例。

  

可用于使用此类压缩或提取文件。的   以下示例将压缩存储在c:\ testing中的文件   文件夹:

Add-Type -Assembly 'System.IO.Compression.FileSystem'
[System.IO.Compression.ZipFile]::CreateFromDirectory('c:\testing', 'c:\testing.zip','Optimal',$false)
  

要提取文件时,请使用ExtractToDirectory方法:

[System.IO.Compression.ZipFile]::ExtractToDirectory('c:\testing.zip', 'c:\newtest')