Azure VPN 网关配置:Get-AzureRmVirtualNetworkGatewayConnection returns ResourceNotFound 错误

Azure VPN Gateway configuration: Get-AzureRmVirtualNetworkGatewayConnection returns ResourceNotFound error

我正尝试按照 here 过程在 Azure Powershell 中配置 VPN。当运行宁以下命令

$connection6 = Get-AzureRmVirtualNetworkGatewayConnection -Name <myconnectionname> -ResourceGroupName <myresourcegroupname>

我收到错误

Get-AzVirtualNetworkGatewayConnection: Resource group '' could not be found.

但是当我运行命令时:

az group show --name "<myresourcegroupname>"

return值为资源组的对象描述:

> {
>   "id": "/subscriptions/<active subscription id>/resourceGroups/<myresourcegroupname>",
>   "location": "<mylocation>",
>   "managedBy": null,
>   "name": "<myresourcegroupname>",
>   "properties": {
>     "provisioningState": "Succeeded"   },
>   "tags": null,
>   "type": "Microsoft.Resources/resourceGroups" 
>}

很明显,该资源组存在并且 powershell 可以通过活动订阅访问(我确认活动订阅确实包含该资源组)。

如何正确识别此命令的资源组 运行?

感谢评论的人。我最终与 Azure 支持人员交谈——网络工程师最初 运行 遇到了同样的问题,并尝试了几个不同的选项。

最终,解决方案变得相当简单,因为问题是帐户下有多个订阅。解决方案只是 运行

Select-azsubscription -SubscriptionID <subscriptionid> 

使用正确的父订阅 ID。正如@Joy Wang 建议的那样,将所有 cmdlet 更新为 newer az versions 也有助于清除错误。