我可以在Powershell ISE (工作流)中成功解压缩.7z,但是当我在Azure运行簿中使用相同的代码时,什么都不会发生:
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)"
}
}调用runbook:
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文件的密码相同。7z文件包含一个名为test.txt的文件。7za.exe是用于7zip的可移植的exe,在Powershell ISE中运行时工作正常。
发布于 2015-04-01 22:13:37
因此,您无法在自动化主机上运行.exe文件。我下载了SevenZipSharp并将blob存储中的.dll文件下载到自动化主机的C:\Temp中,然后使用Add导入程序集,然后从那里运行代码。
https://stackoverflow.com/questions/29382337
复制相似问题