11
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ZIPファイルダウンロード&展開をするPowerShellスクリプト

Posted at

ネットから、ZIPファイルをダウンロードし、展開を行うPowerShellスクリプトを作ってみました。

DownloadUnzipTest.ps1
# 当スクリプトのディレクトリ
$basedir = Convert-Path $(Split-Path -Path $MyInvocation.InvocationName -Parent)
Set-Location $basedir

# Webクライアントオブジェクト生成
$webClient = New-Object System.Net.WebClient

# ZIPファイルダウンロード
$srcUrl = "http://ftp.kddilabs.jp/infosystems/apache/ant/binaries/apache-ant-1.9.2-bin.zip"
$zipName = [System.IO.Path]::GetFileName($srcUrl)
$zipPath = [System.IO.Path]::Combine($basedir, $zipName)
Write-Output "ダウンロード開始 $srcUrl"
$webClient.DownloadFile($srcUrl, $zipPath)

# ZIPファイル展開
$sh = New-Object -ComObject Shell.Application
$unzipDirObj = $sh.NameSpace($basedir)
$zipPathObj = $sh.NameSpace($zipPath)
Write-Output "アーカイブ展開開始 $zipPath"
$unzipDirObj.CopyHere($zipPathObj.Items())

Write-Output "終了"
11
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?