6

In our Azure Cloud Shell, Powershell mode we can't run ps1 files. Although we are doing the same asin the MS Doc. Any Suggestions, what am I doing wrong.

    PS Azure:\> dir


    Directory: Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell


Mode Name
---- ----
.    Build_goal.ps1
.    Test goal_Files.ps1
.    test.ps1


Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell
PS Azure:\> ./test.ps1
./test.ps1 : The term './test.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:1
+ ./test.ps1
+ ~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (./test.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell
PS Azure:\>
Harry Leboeuf
  • 723
  • 12
  • 30

2 Answers2

12

The example below is from Microsoft Docs. The trick is for the shell to be open in the location that the script is saved. This will only work if your script doesn't use libraries that are stored on your local device. You may also need to import any modules needed, e.g. AzureAD

# change to your cloud drive fileshare
cd $HOME\clouddrive

# run the script
.\helloworld.ps1

Hello World!
thommck
  • 146
  • 2
  • 5
1

The default directory for Cloud Shell does not seem to allow script running. Copy the script to "$HOME\clouddrive", change to that dir, then run it from there.

Peter L
  • 2,921
  • 1
  • 29
  • 31