【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]
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2021-11-02 【Azure 应用服务】App Service for Linux 中实现 WebSocket 功能 (Python SocketIO)