powershellのスクリプトから、.zip/.tar.gz形式のファイルを解凍する方法です。

事前に、7-zipのコマンドライン版をダウンロードする必要があります。以下リンクからダウンロードして下さい。
https://sevenzip.osdn.jp/download.html

完成形のスクリプト例は以下の通り。

# 7-zipのパス

$7zip = “C:\~\7z1806-extra\7za.exe”

# 7-zipの実行コマンドの引数を文字列で設定

$arg = “e -p[パスワード] [.zip/.tar.gzのファイルパス]”

# 実行コマンド

Start-Process -FilePath $7zip -ArgumentList $arg

7-zipのコマンドラインの使い方は、7za.exeを引数無で実行すると、usageが出てきます。主な個所を抜粋すると、こんな感じです。

Usage: 7za  <command> [<switches>…] <archive_name> [<file_names>…]

<Commands>

 a : Add files to archive

 e : Extract files from archive (without using directory names)

以下のサイトを参考にしました。

https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1443793929

https://qiita.com/Q11Q/items/c309ff435d59413808d6

Follow me!