gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:15:03 25 4
gpt4 key购买 nike

我可以在 Powershell ISE(工作流程)中成功解压缩 .7z,但是当我在 Azure Runbook 中使用相同的代码时,没有任何反应:

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 文件的密码相同。 test.7z 文件包含一个名为 test.txt 的文件。 7za.exe 是 7zip 的可移植 exe,在 Powershell ISE 中运行时运行良好。

最佳答案

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

关于azure - 在 Azure 自动化中解压缩 .7z 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29382337/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com