How to import CSV with 2 coumns and run foreach

Anthony Kirit 1 Reputation point

I have a csv file. This is the format and info in a table.

PS C:\ $data | format-table


WT40 WVD-40-nic
WT41 WVD-41-nic

What I would like to do is go through this list and foreach NAME assign the pip PIP. My full list is 100 or so rows.

I know how to assign a pip but I do not know how to do a foreach loop that says take column 1 and assign column 2.

The way to assign a single pip is:

$vnet = Get-AzVirtualNetwork -Name myVMVNet -ResourceGroupName myResourceGroup
$subnet = Get-AzVirtualNetworkSubnetConfig -Name myVMSubnet -VirtualNetwork $vnet
$nic = Get-AzNetworkInterface -Name myVMVMNic -ResourceGroupName myResourceGroup
$pip = Get-AzPublicIpAddress -Name myVMPublicIP -ResourceGroupName myResourceGroup
$nic | Set-AzNetworkInterfaceIpConfig -Name ipconfigmyVM -PublicIPAddress $pip -Subnet $subnet
$nic | Set-AzNetworkInterface

Your help with this is much appreciated. I am just learning PS.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,456 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 45,831 Reputation points
    Import-CSV Some-CSV-File-Name.csv |
            # Use the value in $_.Name to identify the "thing"
            # Use the value in $_.PIP as the value to assign to the "thing"
    0 comments No comments