首页 > 解决方案 > Azure Cloud Shell 运行 ps1 脚本时出现问题

问题描述

在我们的 Azure Cloud Shell、Powershell 模式下,我们无法运行 ps1 文件。尽管我们在 MS Doc 中做同样的事情。任何建议,我做错了什么。

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

标签: azure-cloud-shell

解决方案


下面的示例来自Microsoft Docs。诀窍是在保存脚本的位置打开外壳。这仅在您的脚本不使用存储在本地设备上的库时才有效。您可能还需要导入所需的任何模块,例如 AzureAD

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

# run the script
.\helloworld.ps1

Hello World!

推荐阅读