6

在我们的 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:\>
4

2 回答 2

12

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

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

# run the script
.\helloworld.ps1

Hello World!
于 2018-11-12T11:07:40.670 回答
1

Cloud Shell 的默认目录似乎不允许脚本运行。将脚本复制到“$HOME\clouddrive”,更改为该目录,然后从那里运行它。

于 2019-05-27T22:27:32.703 回答