我正在尝试进行验证。用给定值检查部署的值。我使用RestAPI方法从Azure资源提取vnet值,并从Object转换为json,因为vnet对象给了我空对象(@ {value = System.Object []})。以下是我得到的Json代码:
{
"value": [
{
"properties": "@{virtualNetworkSubnetId=/subscriptions/<XXXX>/resourceGroups/<XXXX>/providers/Microsoft.Network/virtualNetworks/<XXXX>/subnets/<XXXX>; ignoreMissingVnetServiceEndpoint=True; state=Ready}",
"id": "/subscriptions/<XXXX>/resourceGroups/<XXXX>/providers/Microsoft.DBforPostgreSQL/servers/<XXXX>/virtualNetworkRules/<XXXX>",
"name": "<XXXX>",
"type": "Microsoft.DBforPostgreSQL/servers/virtualNetworkRules"
}
]
}
下面的powershell命令是比较该值,但会收到一条错误消息:$ vnet.name和$ vnet.id为$ null
$vnet= ( $vnet | ConvertTo-Json)
It "has this number of vNet Rules defined: $($config.vnetRules.count)"
{
$vnet.count | Should -Be $config.vnetRules.count
}
#$vnet.count is working and giving an success message
foreach ($vnetRule in $config.vNetRules) {
Write-Host $vnet #-> getting Json
Write-Host $vnet.Name #-> return as Empty($null)
Write-Host $vnet.value.Name #-> return as Empty($null)
Write-Host $vnet.id #-> return as Empty($null)
Write-Host $vnet.value.id #-> return as Empty($null)
it "has a vNet rule named: $($vnetRule.ruleName)" {
$vnet.name | Should -Be $vnetRule.ruleName
}
it "has a vNet Rule Subnet ID of: $($vNetRule.subnetId)" {
$vnet.value.id | Should -Be $vNetRule.subnetId
}
}
返回$ null。
答案 0 :(得分:0)