Search code examples
azure-cloud-shell

Azure Cloud Shell Trouble running ps1 Scripts


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

Solution

  • 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!