Azure Cloud Shell Trouble running ps1 Scripts
Asked Answered
C

2

7

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:\>
Carp answered 7/9, 2018 at 21:26 Comment(1)
I can't reappear your error, suggest you can check if there is something wrong with your cmdlet.Langham
V
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!
Vientiane answered 12/11, 2018 at 11:7 Comment(0)
S
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.

Skiba answered 27/5, 2019 at 22:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.