【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select‐AzContext' is not recognized as the name - LuBu0505/My-Code GitHub Wiki

问题描述

Azure Web Job执行Powershell脚本报错 

**Select-AzContext : The term 'Select-AzContext' 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. **

问题解答

根据错误信息,判断是此Web Job执行时,缺失对应的PS模块导致无法正常运行。

针对这种情况,需要通过高级站点(Kudu工具:**https://.scm.chinacloudsites.cn/DebugConsole **)上传 Az.Accounts 到 \home\site\wwwroot 下 image.png

然后,在修改 $Env:PSModulePath 的路径,在其后面添加上 +“;c:\home\site\wwwroot”, 示例如下: image.png

但是,请注意,这样的修改为临时性修改。如果App Service的实例重启后,此处修改会丢失。

所以为了是修改长久有效,可以在Web Job的PowerShell脚本中加入这句话。

$Env:PSModulePath =$Env:PSModulePath + "; c:\home\site\wwwroot" 

如图: image.png

[end]

当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!