cmdlet

Powershell zip形式で圧縮 Compress-Archive

powershellにはzipコマンドが標準装備されていないので代わりにompress-Archiveを使います。以下はカレントフォルダに存在するlambda_function.pyというファイルをカレントフォルダにnew_code2.zipという名前のファイルで圧縮しています。

Compress-Archive -DestinationPath .\new_code2.zip -Path .\lambda_function.py

参考までにですがLinuxのzipコマンドでは zip new_code2.zip lambda_function.py となります。

-- -Path で圧縮対象ファイルを指定
-- -DestinationPath で圧縮ファイル名を指定
test >> pwd

Path
----
D:\aws\test

test >> ls

    Directory: D:\aws\test

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          2023/10/10     0:11           1643 lambda_function.py

test >> Compress-Archive -DestinationPath new_code2.zip -Path .\lambda_function.py
test >> ls

    Directory: D:\aws\test

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          2023/10/10     0:11           1643 lambda_function.py
-a---          2023/10/12     0:33            977 new_code2.zip

--
-- -Forceオプションをつける事で上書き圧縮も可能
--
test >> Compress-Archive -DestinationPath new_code2.zip -Path .\lambda_function.py -Force
test >> ls

    Directory: D:\aws\test

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---          2023/10/10     0:11           1643 lambda_function.py
-a---          2023/10/12     0:37            977 new_code2.zip

test >>

unzip(解凍)はこちら

スポンサーリンク
タイトルとURLをコピーしました