检索模块依赖关系时,PowerShell Gallery的响应不一致

问题描述 投票:0回答:1

我不完全确定这是否是发布此问题的正确位置,但在此处。

因此,我尝试使用PowerShell脚本将PowerShell模块导入Azure自动化帐户。为此,我向PowerShell库调用Rest方法并获取模块详细信息。这是代码示例。

$Url = "https://www.powershellgallery.com/api/v2/Search()?`$filter=IsLatestVersion&searchTerm=%27$ModuleName%27&targetFramework=%27%27&includePrerelease=false&`$skip=0&`$top=40" 
    $SearchResult = (Invoke-RestMethod -Method Get -Uri $Url -UseBasicParsing) | Where-Object { $_.properties.title -eq $ModuleName }
    $moduleVersion = $SearchResult.properties.Version
...
$ModuleContentUrl = "https://www.powershellgallery.com/api/v2/package/$ModuleName/$moduleVersion"
...
$Dependencies = $SearchResult.properties.Dependencies
...
$Dependencies | ForEach-Object {
    if($_ -and $_.Length -gt 0) {
        $Parts = $_.Split(":")
        $DependencyName = $Parts[0]

        # BELOW LINE CAUSING INCONSISTENCY
        $DependencyVersion = $Parts[1].Trim("[").Trim("]").Split(",")[0]


        # SOME CUSTOM LOGIC HERE
    }
}

现在,我看到的不一致是依赖列表在不同的时间以不同的方式出现。以下是我目前看到的一个示例。请注意批量生成的版本号,这两个值具有相同的数字。

enter image description here

但是,我看到有时版本号不是这样的,而是作为普通字符串。如下:

modulename:moduleversion

为什么这种不一致?

谢谢!

powershell azure-automation
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.