簡體   English   中英

Azure Powershell - 根據私有IP找到網卡

[英]Azure Powershell - find the NIC based on the private IP

我對 Azure 和 Powershell 非常陌生。 我需要根據私有 IP 地址找到我的網絡接口。 我找到了“Get-AzNetworkInterface”cmdlet,我希望它只返回包含 IP 的條目。 我注意到 IP 僅存在於“IpConfigurationsText”中,但不存在於僅包含 object 名稱的“IpConfigurations”中。 我不知道這是否正常。 返回的“IpConfigurationText”是一個列表(基於我有限的 python 經驗),具有這樣的字典鍵值對

[
 {
   "Name": "xxxx",
   "Id": "xxxx",
   "PrivateIpAddress": "10.1.2.3",
   ...
 }
]

我想我想根據其內容進行過濾。 我嘗試了以下但沒有成功...

Get-AzNetworkInterface | Where-Object { $_.IpConfigurationsText["PrivateIpAddress"] -contains "10.1.2.3" }
Get-AzNetworkInterface | Where-Object { $_.IpConfigurationsText[0]["PrivateIpAddress"] -eq "10.1.2.3" }

我還嘗試在 output 中僅顯示 IP 而不是字典鍵值對也沒有成功

Get-AzNetworkInterface | select Name,IpConfigurationsText["PrivateIpAddress"]

讓我知道我錯過了什么。

順便說一句,我還發現我可以使用“Out-GridView”來查看和過濾結果,但是當它很大時它並沒有顯示整個 output。 它被截斷了。 我似乎也無法對其進行復制/粘貼...對此也有任何建議嗎?

謝謝! 地番

嘗試這個:

$IP = (Get-AzureRmNetworkInterface -Name $VMName -ResourceGroupName $RGName).IpConfigurations.PrivateIpAddress
$IP = [IP you want to search)
$VMID = (Get-AzNetworkInterface | where {$_.IpConfigurations.PrivateIpAddress -eq $IP}).VirtualMachine.Id
If (!$VMID) {
Write-Host "$IP Not Found"
}ELSE {
$VMName = $VMID.Substring($VMID.LastIndexOf('virtualMachines/')+16)
}

$VMName 將保存具有該私有 IP 的 VM 的純文本名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM