[英]How do I get a list of the active IP-addresses, MAC-addresses and NetBIOS names on the LAN?
[英]how do i get the ip addresses and names of vm in avariable
我想檢索所有名稱為“ server ”的虛擬機以及這些計算機的IP地址的列表。 下面非常適合獲取名稱,但是如何將每個虛擬機的私有IP地址添加到變量中?
$machines = Get-AzureRmVM -ResourceGroupName $resourcegroup | where {$_.Name -like server" + "*"}
Get-AzureRmVM
Cmdlet無法獲取任何VM的IP地址信息。
您必須從Get-AzureRmVM
NetworkInterface名稱,然后將該值傳遞給Get-AzureRmNetworkInterface
Cmdlet以獲得專用IP。
Get-AzureRmVM -ResourceGroupName TestRG | Where-Object {$_.Name -like '*server*'} | ForEach-Object {
$NIC = $_.NetworkProfile.NetworkInterfaces.id -replace '^.*/'
$RGName = $_.NetworkProfile.NetworkInterfaces.id -replace '^.*resourceGroups/(.*)/providers.*','$1'
$IP = (Get-AzureRmNetworkInterface -Name $NIC -ResourceGroupName $RGName).IpConfigurations.PrivateIpAddress
[PSCustomObject]@{VMName = $_.Name ; PrivateIpAddress = $IP}
}
或者,您可以直接調用Get-AzureRmNetworkInterface
並使用VirtualMachine.ID屬性過濾VM。
$Resourcegroup = 'TestRG'; $VmName = 'server'
Get-AzureRmNetworkInterface | Where-Object { $_.VirtualMachine.ID -match "^.*resourceGroups/$Resourcegroup.*virtualMachines/.*$VmName.*" } |
Select-Object @{L='VMName';ex = {$_.VirtualMachine.Id -replace '^.*/'}}, @{L='PrivateIpAddress';ex = {$_.IpConfigurations.PrivateIpAddress}}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.