Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:\>
like image 273
Harry Leboeuf Avatar asked Sep 07 '18 21:09

Harry Leboeuf


People also ask

Can we run PowerShell script on Azure cloud shell?

Azure CLI commandsYou can use both in Cloud Shell in PowerShell, and you can use both remotely at your workstation to manage the Azure cloud. If it's resources in Azure that you want to manage, then use Azure CLI; and if you need to manage Windows Servers, then use Azure PowerShell.


2 Answers

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!
like image 92
thommck Avatar answered Jan 02 '23 21:01

thommck


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.

like image 45
Peter L Avatar answered Jan 02 '23 19:01

Peter L