我们可以在Azure应用程序服务上部署为WebJob的.NET控制台应用程序中的Runspace内部执行AZ PowerShell模块命令吗?

发布于 2025-01-25 09:19:28 字数 1144 浏览 3 评论 0原文

我有一个在Azure App Service中运行的WebJob,该服务使用Runspace执行Azure PowerShell模块命令。在本地工作正常,因为我可以使用Windows PowerShell直接安装AZ模块,但是当我将其部署到Azure时,它会失败。

最初,当我执行connect -azAccount -Identity

Connect-AzAccount : The term 'Connect-AzAccount' is not recognized as the name of a cmdlet

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

我会 遇到关注错误模块:

    runSpace.Open();

    RunspaceInvoke scriptInvoker = new RunspaceInvoke();
    scriptInvoker.Invoke("Install-PackageProvider Nuget -MinimumVersion 2.8.5.201 -Force -Scope CurrentUser");
    scriptInvoker.Invoke("Import-PackageProvider Nuget");
    scriptInvoker.Invoke("Install-Module Az.Websites -Force -AllowClobber -Scope CurrentUser");
    scriptInvoker.Invoke("Import-Module Az.Websites");
    scriptInvoker.Invoke("Install-Module Az.Storage -Force -AllowClobber -Scope CurrentUser");
    scriptInvoker.Invoke("Import-Module Az.Storage");

那么是否可以在AppService中执行AZ PowerShell模块命令?

I've a webjob running in an azure app service that uses runspace to execute azure powershell module commands. Locally it's working fine because I can install az module directly using Windows powershell but when I deploy it to Azure, it fails.

Initially I was getting following error when I was executing Connect-AzAccount -Identity

Connect-AzAccount : The term 'Connect-AzAccount' is not recognized as the name of a cmdlet

Then I tried to install az module inside of a runspace and I started getting another error:

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Here is how I'm trying to install az module:

    runSpace.Open();

    RunspaceInvoke scriptInvoker = new RunspaceInvoke();
    scriptInvoker.Invoke("Install-PackageProvider Nuget -MinimumVersion 2.8.5.201 -Force -Scope CurrentUser");
    scriptInvoker.Invoke("Import-PackageProvider Nuget");
    scriptInvoker.Invoke("Install-Module Az.Websites -Force -AllowClobber -Scope CurrentUser");
    scriptInvoker.Invoke("Import-Module Az.Websites");
    scriptInvoker.Invoke("Install-Module Az.Storage -Force -AllowClobber -Scope CurrentUser");
    scriptInvoker.Invoke("Import-Module Az.Storage");

So is it possible to execute az powershell module command in appservice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

任谁 2025-02-01 09:19:28
  • 有多种方法可以解决该问题,以下是一些决议。

修复1:
解决问题运行以下命令。

Import-Module Az.Accounts

当您执行上述命令时,它将提示您获得凭据。

修复2:

  • 安装模块AZ。
    通过使用以下powershell cmdlet,
Import-Module Az
  • 连接到下面的 azaccount
Connect-AzAccount
  • 您可以检查工作解决方案来自此处。

  • 还要检查此 so 进行了相关讨论。

  • There are multiple ways to address the issue, below are the few resolutions.

Fix 1:
To resolve the issue run the below command.

Import-Module Az.Accounts

When you executed the above command, it will prompt you for the credentials.

Fix 2:

  • Install the Module Az.
    By using the below PowerShell cmdlet,
Import-Module Az
  • Connect to the AzAccount like below,
Connect-AzAccount
  • You can check the worked solution from here.

  • Also check this SO with the related discussions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文