0

I'm trying to download and run a PowerShell script (from blob storage) using the Run Powershell artifact on an existing VM in Azure DevTest labs.

I get the following error and I assume I am doing something stupid.

& : 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

Here is my setup...

Image showing artifact setup with URL and script name matching

I have also tried the JSON array syntax, which gave the same result, and an invalid URL which gave a 404 error so it seems as if it is downloading my script but then failing to find it.

drs9222
  • 4,448
  • 3
  • 33
  • 41

1 Answers1

0

Below is info I wrote a while back. Few items to note:

  • Folder structure is not supported as of this writing. Therefore, script needs to be at the root of the container
  • Ensure your blob is public

First you will need your file in Azure storage. Once uploaded in your container, click the file to get to its properties and copy the URL field.

As an example, I have created the following Run.ps1 script file and uploaded it to storage as a blob:

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

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

Now, while adding the 'Run PowerShell' artifact to the VM, we provide the following information:

File URI(s): URL field copied from earlier step. (eg. https://myblob.blob.core.windows.net/mycontainer/Run.ps1)

Script to Run: Name of the PS1 script, (eg. Run.ps1)

Script Arguments: Arguments as you would write them at the end of your command (eg. -drive "d:\" -folderName "MyFolder")

joerage
  • 4,863
  • 4
  • 38
  • 48
  • I saw this in my research before I posted. My script isn't even being run. However, it does appear to be being downloaded. – drs9222 Aug 22 '18 at 12:20