0

I'm Attempting to Unzip A folder located on a shared drive to the root of C:\ on a remote PC but keep getting errors, how do i correct this 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"

This returns the following error:

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
Federico Grandi
  • 6,785
  • 5
  • 30
  • 50
Khalifa96
  • 47
  • 2
  • 10
  • Don't know why, but the error shows the command is 'eating' your first backslash of the UNC path. Have you tried not using `-LiteralPath` but instead use `-Path`? Otherwise, what happens if you use double quotes `"` around the path instead of single quotes? – Theo Mar 27 '19 at 16:38

1 Answers1

0

A few things here:

  1. Remember Windows balks are dropping stuff in the root c:.
  2. So, are we to assume that \LNApps is a server name and \APPS is a folder share configured on that server?
  3. Lastly, unless that server is running PowerShell v5, that Expand-Archive cmdlet is not there.

Hence this...

: 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

If that cmdlet is not there, you need to use the .Net namespace, System.IO.Compression.FileSystem, to deal with this use case.

can be used to either compress or extract files using this class. The following example will compress the files stored in the c:\testing folder:

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

When you want to extract files, use the ExtractToDirectory method:

[System.IO.Compression.ZipFile]::ExtractToDirectory('c:\testing.zip', 'c:\newtest')
postanote
  • 15,138
  • 2
  • 14
  • 25