Forum Discussion
Alan2022
May 11, 2022Iron Contributor
Do you have any faster ps script to get azure private ip address?
Hi Community, Do you have any faster ps script to get azure private ip address? Extracting too many vms makes this script slow. Thanks. My Code. $nin = (Get-AzVM -Name "VMNAME").NetworkP...
- May 11, 2022
Hi, Alan.
Try the following.
It's not necessarily that much better as you are forced to do client-side filtering for IP information (at least with these commandlets) but it should be a bit faster through not having to make two REST calls (one for fetching the VM data, and a second for the interface data.)
Get-AzNetworkInterface | Where-Object { $_.VirtualMachine -and $_.IPConfigurations -and $_.IPConfigurations.PrivateIPAddress } | Select-Object -Property @{n="Name"; e={ $_.VirtualMachine.Id.Split("/")[-1] }}, @{n="PrivateIPAddress"; e= { $_.IpConfigurations.PrivateIPAddress }}Cheers,
Lain
Alan2022
May 11, 2022Iron Contributor
LainRobertson
Hi Lain,
I tried your code it was really fast i was amazed. But its hard to read it. If i want to filter by the VM ResourceGroupName where should i do this? Thanks.
Hi Lain,
I tried your code it was really fast i was amazed. But its hard to read it. If i want to filter by the VM ResourceGroupName where should i do this? Thanks.
Alan2022
May 12, 2022Iron Contributor
LainRobertson
Hi Lain,
I get it just add it in the Where-Object.
Get-AzNetworkInterface | Where-Object { $_.ResourceGroupName -Match "ResourceGroupName" -and $_.VirtualMachine -and $_.IPConfigurations -and $_.IPConfigurations.PrivateIPAddress }
Thank you very much.
Keep up the good job. .☺☺☺
Hi Lain,
I get it just add it in the Where-Object.
Get-AzNetworkInterface | Where-Object { $_.ResourceGroupName -Match "ResourceGroupName" -and $_.VirtualMachine -and $_.IPConfigurations -and $_.IPConfigurations.PrivateIPAddress }
Thank you very much.
Keep up the good job. .☺☺☺