【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select-AzContext' is not recognized as the name

问题描述

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://<your app service name>.scm.chinacloudsites.cn/DebugConsole )上传 Az.Accounts 到 \home\site\wwwroot 下

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

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

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

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

如图:

 

 

 

[end]

 

 

posted @   路边两盏灯  阅读(24)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2021-11-02 【Azure 应用服务】App Service for Linux 中实现 WebSocket 功能 (Python SocketIO)
点击右上角即可分享
微信分享提示