1
我可以成功解压一个.7z压缩在PowerShell中ISE(工作流),但是当我在Azure中运行手册使用相同的代码,没有任何反应:解压在Azure的自动化.7z压缩文件
workflow Unzip-File
{
Param([Parameter(mandatory=$true)][String]$zipFileSource,
[Parameter(mandatory=$true)][String]$destinationFolder,
[Parameter(mandatory=$true)][String]$password,
[Parameter(mandatory=$true)][String]$pathTo7zipExe)
InlineScript
{
Write-Output "${using:zipFileSource} exists? - $(Test-Path ${using:zipFileSource})"
Write-Output "${using:destinationFolder} exists? - $(Test-Path ${using:destinationFolder})"
Write-Output "${using:pathTo7zipExe} exists? - $(Test-Path ${using:pathTo7zipExe})"
$passwordSwitch = "-p" #this is needed because otherwise the password is literally $password rather than the string stored in that variable.
$destinationDirSwitch = "-o"
& ${using:pathTo7zipExe} x ${using:zipFileSource}$destinationDirSwitch${using:destinationFolder}$passwordSwitch${using:password} -y #-y means if prompted for yes/no, choose yes automatically.
$fileName = "test.txt"
$destinationPath = [System.IO.Path]::Combine(${using:destinationFolder}, $fileName)
Write-Output "$destinationPath exists? - $(Test-Path $destinationPath)"
}
}
调用运行手册:
Unzip-File `
-destinationFolder C:\Temp `
-Password "ThePassword" `
-pathTo7zipExe 'C:\Temp\7za.exe' `
-zipFileSource 'C:\Temp\test.7z'
输出:
C:\Temp\test.7z exists? - True
c:\temp exists? - True
C:\Temp\7za.exe exists? - True
c:\temp\test.txt exists? - False
正如你可以看到包含.7z压缩(test.txt的)中的文件不被前牙牙。
这些文件位于自动化主机的C:\ Temp文件夹中(我从blob存储中将它们下载到那里)。我再次检查密码是否与用于压缩.7z文件的密码相同。 test.7z文件包含一个名为test.txt的文件。 7za.exe是7zip的便携式exe文件,在Powershell ISE中运行时工作良好。
如果您不想管理Azure Blob存储中的文件或每次运行Runbook时都必须从blob存储下载.dlls,则可以将SevenZipSharp的.dlls包装到PowerShell模块中,并将该模块导入Azure自动化。 – Joe 2015-04-03 03:01:20