Pass Ethernet Interface Alias as value to create a secondary IP on that Interface

I have a couple of VM's in Azure that I need to temporary add secondary IP in the Windows Server (guest os). I don't know the Interface Aliases of NIC's present in that systems (systems will be newly generated by ASR), I know the primary IP's assigned.

I need to add secondary IP to only one existing NIC in the OS, I plan to use command: New-NetIPAddress -IPAddress xxx.xxx.xxx.xxx -InterfaceAlias "NAME" -SkipAsSource $true

How can I grab name of Interface Alias from this NIC and put on command above, or maybe there is some other solution to do that?

Thanks from advance for every help.

Current code:

$PrimaryIP = "10.20.30.5"
$NetworkInterface = Get-NetIPConfiguration | Where-Object { $_.IPv4Address.IPAddress -eq $PrimaryIP }

$InterfaceAlias = $NetworkInterface.InterfaceAlias

$SecondaryIP = "10.20.30.6"  
New-NetIPAddress -IPAddress $SecondaryIP -InterfaceAlias $InterfaceAlias -PrefixLength 24 -SkipAsSource $false

Start-Sleep -Seconds 60

New-NetRoute -DestinationPrefix 0.0.0.0/0 -InterfaceAlias $InterfaceAlias -NextHop 10.20.30.1


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation