Loop Powershell with two corresponding variables

Anthony Kirit 21 Reputation points
2021-06-28T16:00:37.037+00:00

I have a powershell set of commands listed below. This works great for one nic and it's associatedone public IP. I need to make it work for a set from csv, shown below.

I'm new to this and am not sure how to loop through, with foreach I would imagine.

$vnet = Get-AzVirtualNetwork -Name WestUS2vnet -ResourceGroupName WestUS
$subnet = Get-AzVirtualNetworkSubnetConfig -Name Desktops -VirtualNetwork $vnet
$publicIP = Get-AzPublicIpAddress -name WT1 -ResourceGroupName WVDARM
$nic = Get-AzNetworkInterface -Name WVD-1-nic -ResourceGroupName WVDARM
$nic | Set-AzNetworkInterfaceIpConfig -Name ipconfig -Subnet $subnet -Primary -PublicIpAddress $publicIP
$nic | Set-AzNetworkInterface

This associates the pip WT1 to the nic WVD-1-nic. Below is a CSV for 27 pips and 27 nics. I need to assign the pips to the corresponding nics.

109972-image.png

Your help is greatly appreciated

Windows for business | Windows Server | User experience | PowerShell
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2021-06-28T18:10:22.977+00:00

    So, something like this?

    Import-Csv c:\junk\wt.csv |
        ForEach-Object{
            Write-Host "Do something with " $_.NAME " and " $_.NIC
        }
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.