首页 > 解决方案 > “运行 PowerShell”工件未能安装 CommandNotFoundException

问题描述

我正在尝试使用Azure 开发测试实验室中现有 VM 上的Run Powershell工件下载并运行 PowerShell 脚本(从 blob 存储)。

我收到以下错误,我认为我在做一些愚蠢的事情。

& : The term './script.ps1' is not recognized as the name of a cmdlet, 
function, script file, or operable program. Check the spelling of the name, or 
if a path was included, verify that the path is correct and try again.
At line:1 char:3
+ & ./script.ps1
+   ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (./script.ps1:String) [], Comman 
   dNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

这是我的设置...

显示具有 URL 和脚本名称匹配的工件设置的图像

我还尝试了 JSON 数组语法,它给出了相同的结果,以及一个无效的 URL,它给出了 404 错误,所以看起来好像它正在下载我的脚本,但后来找不到它。

标签: azurepowershellazure-blob-storageartifactazure-devtest-labs

解决方案


以下是我前一阵子写的信息。需要注意的几点:

  • 在撰写本文时,不支持文件夹结构。因此,脚本需要在容器的根目录下
  • 确保您的 blob 是公开的

首先,您需要将文件保存在 Azure 存储中。在您的容器中上传后,单击该文件以访问其属性并复制 URL 字段。

例如,我创建了以下 Run.ps1 脚本文件并将其作为 blob 上传到存储:

param ( [string]$drive = "c:\" )
param ( [string]$folderName = "DefaultFolderName" )

New-Item -Path $drive -Name $folderName -ItemType "directory"

现在,在将“运行 PowerShell”工件添加到 VM 时,我们提供以下信息:

文件 URI(s):从前面的步骤复制的 URL 字段。(例如https://myblob.blob.core.windows.net/mycontainer/Run.ps1

要运行的脚本: PS1 脚本的名称,(例如 Run.ps1)

脚本参数:在命令末尾编写的参数(例如 -drive "d:\" -folderName "MyFolder")


推荐阅读