2

I've tried a simple:

wget https://www.dropbox.com/sh/dropboxStuff/dropboxStuff?dl=1 -O DirectoryName

But it's downloading a zip file.

  • What is the best way to download and unzip with only powershell commands?
  • Could this be done in one line?
Giulio Caccin
  • 2,962
  • 6
  • 36
  • 57

2 Answers2

3

In Powershell v5

Expand-Archive c:\a.zip -DestinationPath c:\a

To know your PS vesion

$PSVersionTable.PSVersion 

If you don't have PS v5

Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
    param([string]$zipfile, [string]$outpath)

    [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}

Unzip "C:\a.zip" "C:\a"

Source: This Question

Stefano.Maffullo
  • 801
  • 8
  • 21
  • Is wget the best way to do the download in powershell? how can I pipe the result of the download to this command? – Giulio Caccin Aug 01 '17 at 12:16
  • 1
    @GiulioCaccin Expand-Archive accepts pipeline input. So you can do `Get-Item [zipfile] | Expand-Archive -DestinationPath C:\etc` – Maximilian Burszley Aug 01 '17 at 12:19
  • 1
    @GiulioCaccin I'd suggest using `Invoke-WebRequest` over `wget`. By default, `wget` is aliased to that cmdlet but one shouldn't use aliases in scripts, and if you don't have that alias and you're really using `wget`, it will be an external dependency which makes your script less portable. – alroc Aug 01 '17 at 12:26
  • Thank you @alroc! If you edit the response with the oneline command i can mark this as the answer. – Giulio Caccin Aug 01 '17 at 12:33
2

To do this in one line with PowerShell 5's Expand-Archive cmdlet:

Invoke-WebRequest -Uri https://www.dropbox.com/sh/dropboxStuff/dropboxStuff?dl=1 -O temp.zip; Get-Item temp.zip | Expand-Archive -DestinationPath "FolderName"; Remove-Item temp.zip

You may be able to do it by piping Invoke-WebRequest to Expand-Archive with -PassThru but I haven't been able to make it work yet.

alroc
  • 27,574
  • 6
  • 51
  • 97