Azure Powershell命令无法在我的资源组下找到我的VM?

时间:2017-01-15 22:55:13

标签: azure azure-powershell

我正在尝试更改Azure中的Ubuntu VM上的TCP端口超时,并且正在关注this guide这样做,但是我似乎陷入了步骤8,我必须键入以下命令:

Get-AzureRmVM -Name "digitron" -ResourceGroup "DIGITRON-RG" | Get-AzureRmPublicIpAddress

它吐出以下错误:

  

Get-AzureRmPublicIpAddress:资源组下的资源“Microsoft.Network/publicIPAddresses/digitron”   找不到'DIGITRON-RG'。   StatusCode:404   ReasonPhrase:未找到   OperationID:'5031da35-262c-4e1a-a85b-885a6a0fd36c'   在行:1 char:63   + ...“digitron”-ResourceGroup“DIGITRON-RG”| GET-AzureRmPublicIpAddress   + ~~~~~~~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:CloseError:(:) [Get-AzureRmPublicIpAddress],NetworkCloudException       + FullyQualifiedErrorId:Microsoft.Azure.Commands.Network.GetAzurePublicIpAddressCommand

这里有什么奇怪的是如果我运行命令Get-AzureRmVm,powershell会吐回来:

  

ResourceGroupName名称位置VmSize OsType NIC ProvisioningState
  DIGITRON-RG digitron eastus Standard_DS2_v2 Linux digitron727成功

现在阅读错误让我觉得VM本身没有公共IP地址,但我已将其设置在Azure门户中,如图所示(其中显示40.71.98.172等):

in this image

为什么Powershell会给我这个错误?

2 个答案:

答案 0 :(得分:0)

  

The Resource' Microsoft.Network/publicIPAddresses/digitron'下   资源组' DIGITRON-RG'没找到。

由于Get-AzureRmPublicIpAddress无法获得正确的参数,因此该错误意味着资源无法在DIGITRON-RG中找到。对于测试,我们可以使用Get-AzureRmResource来测试资源是否存在:

PS > Get-AzureRmResource |  ?{$_.name = "digitron"}

顺便说一句,命令Get-AzureRmPublicIpAddress需要参数: -Name (公共IP地址的名称), -ResourceGroupName (名称为资源组)

PS > Get-AzureRmPublicIpAddress -Name "jason-ip" -ResourceGroupName "jason"


Name                     : jason-ip
ResourceGroupName        : jason
Location                 : eastus
Id                       : /subscriptions/5xxxxabb-222b-49c3-9488-0361e29a7b15/resourceGroups/jason/providers/Microsoft.Network/publicIPAddresses/jason-ip
Etag                     : W/"5a7200b2-7c2b-4c7a-be27-0bbb7c8f4665"
ResourceGuid             : 32xxxf-750a-46a4-abda-c25xxx2b64
ProvisioningState        : Succeeded
Tags                     :
PublicIpAllocationMethod : Dynamic
IpAddress                : 13.92.255.103
PublicIpAddressVersion   : IPv4
IdleTimeoutInMinutes     : 30
IpConfiguration          : {
                             "Id": "/subscriptions/5xxxxb-222b-49c3-9xx8-0361e29a7b15/resourceGroups/jason/providers/Microsoft.Network/networkInterfaces/jason647/ipConfigurations/ipconfig1"
                           }
DnsSettings              : null

我们可以使用此命令直接获取公共IP,并将timrout增加到30分钟。

答案 1 :(得分:0)

以下是我用于获取Azure ARM VM的专用和公共IP的脚本:

$rg = Get-AzureRmResourceGroup -Name "MyResourceGroup01"
$vm = Get-AzureRmVM -ResourceGroupName $rg.ResourceGroupName -Name "MyVM01"
$nic = Get-AzureRmNetworkInterface -ResourceGroupName $rg.ResourceGroupName -Name $(Split-Path -Leaf $VM.NetworkProfile.NetworkInterfaces[0].Id)
$nic | Get-AzureRmNetworkInterfaceIpConfig | Select-Object Name,PrivateIpAddress,@{'label'='PublicIpAddress';Expression={Set-Variable -name pip -scope Global -value $(Split-Path -leaf $_.PublicIpAddress.Id);$pip}}
(Get-AzureRmPublicIpAddress -ResourceGroupName $rg.ResourceGroupName -Name $pip).IpAddress

#Output:    
Name      PrivateIpAddress PublicIpAddress
----      ---------------- ---------------
ipconfig1 10.0.0.10        MyVM01-pip

40.80.217.1
相关问题