Thank you very much LucD, that worked perfectly.
Original Message:
Sent: May 22, 2024 03:43 AM
From: LucD
Subject: How to get filter and get particular VM IP
Ok, then try like this
Get-VM |Where-Object { $_.Guest.IPAddress -match "^172\.27\.1\." } |Select-Object Name, @{N = "IP_Address"; E = { $_.Guest.IPAddress.where{$_ -match "^172\.27\.1\."}}}
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Original Message:
Sent: May 22, 2024 01:09 AM
From: ganapa2000
Subject: How to get filter and get particular VM IP
LucD, I am getting all 4 IP address from the above, but I want only IP address that starts with 172.27.1 (172.27.1.19)
Original Message:
Sent: May 21, 2024 01:05 PM
From: LucD
Subject: How to get filter and get particular VM IP
The -match operator expects a RegEx.
Try with this RegEx
Get-VM disktest |
Where-Object {$_.Guest.IPAddress -match "^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.1\."} |
Select Name, @{N="IP_Address";E={@($_.Guest.IPAddress)}}|
Select -Expandproperty "IP_Address"
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Original Message:
Sent: May 21, 2024 02:18 AM
From: ganapa2000
Subject: How to get filter and get particular VM IP
Hi,
I have multiple VMs which has multiple IP address with different subnets. How can I query and get particular IP subnet of the particular VM
for example, disktest has two NICs where one NIC is having 172.27.18.x subnet and other one is having 172.27.1.x
now, I want to get only 172.27.1.x IP from a particular VM
I tried as below, it is not retrieving the particular subnet IP
Get-VM disktest | Where-Object {$_.Guest.IPAddress -match "172.27.6." -or $_.Guest.IPAddress -match "172.27.1.*"} | Select Name, @{N="IP_Address";E={@($_.Guest.IPAddress)}}| Select -Expandproperty "IP_Address"
Please help!!