Согласно встроенным файлам справки и интерактивной документации PowerShell, командлет Expand-Archive не предоставляет средств для этого варианта использования и не имеет возможности добавить пароль.
Все командлеты, которые обеспечить такой механизм, иметь переключатель «-Credential».
# Find all cmdlets / functions with a target parameter
Get-Command -CommandType Function |
Where-Object { $_.parameters.keys -match 'credential'} |
Out-GridView -PassThru -Title 'Available functions which has a specific parameter'
Get-Command -CommandType Cmdlet |
Where-Object { $_.parameters.keys -match 'credential'} |
Out-GridView -PassThru -Title 'Results for cmdlets which has a specific parameter'
Даже собственное пространство имен. Net, ' System.IO.Compression ' не предоставляет его. Хотя есть проект, который давно существует для этого. Net.
О DotNetZip - Документация DotNetZip
Старый проект DotNetZip - CodeProject
Разветвленная версия Галерея NuGet | DotNetZip 1.13.5
Тем не менее, это не спецификация PowerShell c. Это просто автономный «.exe» для использования, как 7zip, WinZip и т. Д. c. Тем не менее, если вы хотите покопаться в исходном коде и превратить его в используемый модуль, это решение для вас.
Примечание:
В MS powershellgallery.com уже есть модули, которые уже сделали это.
Find-Package -Name '*DotNetZip*'
Name Version Source Summary
---- ------- ------ -------
DotNetZip 1.13.5 nuget.org A library for dealing with zip, bzip and zlib from .Net
DotNetZip.Reduced 1.9.1.8 nuget.org DotNetZip is an easy-to-use, FAST, FREE class library and toolset for manipulating zip files or ...
XAct.IO.Compression.DotNetZip 1.1.17040.3290 nuget.org An XActLib assembly: a library to work with the essentials of DotNetZip.
VirtualPath.DotNetZip 0.3.9 nuget.org DotNetZip library wrapper for VirtualPath
DotNetZip.NetStandard 1.12.0 nuget.org A library for dealing with zip, bzip and zlib from .Net
DotNetZip.Zlib.vNextUnofficial 1.9.8.3 nuget.org DotNetZip vNext port
DotNetZip.Zip.vNextUnofficial 1.9.8.3 nuget.org DotNetZip vNext port
DotNetZip.Android 1.13.5 nuget.org A library for dealing with zip, bzip and zlib from .Net
DotNetZip.iOS 1.13.5 nuget.org A library for dealing with zip, bzip and zlib from .Net
Bardock.Utils.Web.Mvc.DotNe... 1.0.0 nuget.org MVC and DotNetZip utilities
...
RI.Framework.Extensions.Dot... 0.7.0 nuget.org Decoupling & Utilities Framework
DotNetZipforWindows8.1 1.0.0 nuget.org i make same changes to make this is a package for zip file with password for windows 8.1 and win...
Итак, используйте указанные выше модули или вам нужно Оболочка для инструмента 3P, такого как 7zip, et c ...
C:\>"C:\Program Files\7-Zip\7z.exe" a D:\Temp\mytest.zip D:\Temp\mytest.txt -pSecret
7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21
Scanning the drive:
1 file, 64 bytes (1 KiB)
Creating archive: D:\Temp\mytest.zip
Add new data to archive: 1 file, 64 bytes (1 KiB)
Files read from disk: 1
Archive size: 230 bytes (1 KiB)
Everything is Ok
C:\>"C:\Program Files\7-Zip\7z.exe" x D:\Temp\mytest.zip D:\Temp\mytest.txt -pSecret
7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21
Scanning the drive for archives:
1 file, 230 bytes (1 KiB)
Extracting archive: D:\Temp\mytest.zip
--
Path = D:\Temp\mytest.zip
Type = zip
Physical Size = 230
No files to process
Everything is Ok
Files: 0
Size: 0
Compressed: 230
Существует несколько статей о том, как правильно использовать внешние cmds с PowerShell.
PowerShell: запуск исполняемых файлов
Решение проблем с внешними командными строками в PowerShell
Лучшие 5 советов по запуску внешних команд в Powershell
Использование Windows PowerShell для запуска старых инструментов командной строки (и их самых странных параметров)
Выполнение внешних команд в PowerShell выполнено правильно
https://mnaoumov.wordpress.com/2015/03/31/execution-of-external-commands-native-applications-in-powershell-done-right-part-2
https://mnaoumov.wordpress.com/2015/04/05/execution-of-external-commands-native-applications-in-powershell-done-right-part-3
Цитирование также важно при этом
Особенности квотирования
Итак, вы получите в итоге это ...
# Using the call operator
& 'C:\Program Files\7-Zip\7z.exe' a 'D:\Temp\mytest.zip' 'D:\Temp\mytest.txt' -pSecret
& 'C:\Program Files\7-Zip\7z.exe' x 'D:\Temp\mytest.zip' 'D:\Temp\mytest.txt' -pSecret
Или используя Start-Process с той же строкой.