首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Azure自动化中解压缩.7z文件

在Azure自动化中解压缩.7z文件
EN

Stack Overflow用户
提问于 2015-04-01 03:24:08
回答 1查看 1.8K关注 0票数 1

我可以在Powershell ISE (工作流)中成功解压缩.7z,但是当我在Azure运行簿中使用相同的代码时,什么都不会发生:

代码语言:javascript
运行
复制
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:

代码语言:javascript
运行
复制
Unzip-File `
        -destinationFolder C:\Temp `
        -Password "ThePassword" `
        -pathTo7zipExe 'C:\Temp\7za.exe' `
        -zipFileSource 'C:\Temp\test.7z'

输出:

代码语言:javascript
运行
复制
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中运行时工作正常。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-01 22:13:37

因此,您无法在自动化主机上运行.exe文件。我下载了SevenZipSharp并将blob存储中的.dll文件下载到自动化主机的C:\Temp中,然后使用Add导入程序集,然后从那里运行代码。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29382337

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档