【发布时间】:2023-03-28 16:51:01
【问题描述】:
要从我们的 Azure DevOps 管道自动配置 Azure 数据资源管理器数据库,我们使用 PowerShell 模块 Az.Kusto。 我们用于执行 KQL 脚本的函数是 New-AzKustoScript,它仅在最新版本的 Az.Kusto 中可用,因此我们将以下指令作为我们的 PowerShell 脚本的一部分运行,该脚本稍后会调用 New-AzKustoScript:
Install-Module -Name Az.Kusto -RequiredVersion "2.0.0" -Force -Scope CurrentUser -AllowClobber
在我的开发机器上本地运行,但是当我们将此脚本作为 Azure DevOps Pipeline 的一部分运行时,我们会收到以下异常
2021-06-08T09:15:42.1278098Z $RuntimeException/ at System.Management.Automation.TypeOps.ResolveTypeName(ITypeName typeName, IScriptExtent errorPos)
2021-06-08T09:15:42.1413212Z at System.Management.Automation.Language.Compiler.NewOutputTypeAttribute(AttributeAst ast)
2021-06-08T09:15:42.1462865Z at System.Management.Automation.Language.Compiler.GetAttribute(AttributeAst attributeAst)
2021-06-08T09:15:42.1465059Z at System.Management.Automation.Language.ScriptBlockAst.<System-Management-Automation-Language-IParameterMetadataProvider-GetScriptBlockAttributes>d__68.MoveNext()
2021-06-08T09:15:42.1466223Z at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
2021-06-08T09:15:42.1485936Z at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
2021-06-08T09:15:42.1503023Z at System.Management.Automation.CompiledScriptBlockData.InitializeMetadata()
2021-06-08T09:15:42.1633625Z at Microsoft.Azure.PowerShell.Cmdlets.Kusto.Runtime.PowerShell.GetScriptCmdlet.<ProcessRecord>b__16_0(FunctionInfo fi)
2021-06-08T09:15:42.1635647Z at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
2021-06-08T09:15:42.1637257Z at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
2021-06-08T09:15:42.1693162Z at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
2021-06-08T09:15:42.1719336Z at Microsoft.Azure.PowerShell.Cmdlets.Kusto.Runtime.PowerShell.GetScriptCmdlet.ProcessRecord()
2021-06-08T09:15:43.3829832Z ##[error]Unable to find type [Microsoft.Azure.PowerShell.Cmdlets.Kusto.Models.Api202101.IOperation].
2021-06-08T09:15:43.5666125Z ##[error]PowerShell exited with code '1'.
任何帮助或提示将不胜感激。
更新:
-
在安装前卸载 Az.Kusto 失败并显示错误消息 “没有删除任何模块。验证要删除的模块的规范是否正确,并且这些模块存在于运行空间中。”
-
我看到在目录 C:\Modules\az_5.7.0 中安装了 Az.Kusto 的 1.0.1 版本。
-
另外,当我在版本 2.0.0 中安装 Az.Kusto 时,此版本安装在 C:\Users\VssAdministrator\Documents\WindowsPowerShell\Modules 中
-
当我使用 Scope AllUsers 安装 Az.Kusto 时,模块显示在 C:\Program Files\WindowsPowerShell\Modules 下
-
当我通过指定所需版本或传递 -Name 和路径 (Import-Module -Name "C:\Program Files\WindowsPowerShell\Modules\Az.Kusto\2.0.0\Az. Kusto.psm1" -Force -Global) 我得到同样的错误。
-
模块 Az.Accounts 安装在 2.3.0 版本的目录 C:\Modules\az_5.7.0
-
我们在与 Install-Module 和 Import-Module 调用不同的 PowerShell 脚本中调用 New-AzKustoScript。这可能是个问题吗?
【问题讨论】:
-
确保在安装后手动导入:
Import-Module Az.Kusto -RequiredVersion 2.0.0 -Force -
我们这样做了,但不幸的是错误保持不变。
标签: azure powershell azure-data-explorer kql