【问题标题】:The 'Run PowerShell' artifact failed to install with CommandNotFoundException“运行 PowerShell”工件未能安装 CommandNotFoundException
【发布时间】:2018-08-21 19:34:04
【问题描述】:

我正在尝试在 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

这是我的设置...

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

【问题讨论】:

    标签: azure powershell azure-blob-storage artifact azure-devtest-labs


    【解决方案1】:

    以下是我不久前写的信息。 需要注意的几点:

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

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

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

    param ( [string]$drive = "c:\" )
    param ( [string]$folderName = "DefaultFolderName" )
    
    New-Item -Path $drive -Name $folderName -ItemType "directory"
    

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

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

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

    脚本参数:参数,就像您在命令末尾写的那样(例如 -drive "d:\" -folderName "MyFolder")

    【讨论】:

    • 我在发帖前的研究中看到了这一点。我的脚本甚至没有运行。但是,它似乎正在被下载。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-20
    • 2014-01-23
    • 2012-03-01
    • 2018-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多