Import-CSV Some-CSV-File-Name.csv |
ForeEach-Object{
# Use the value in $_.Name to identify the "thing"
# Use the value in $_.PIP as the value to assign to the "thing"
}
How to import CSV with 2 coumns and run foreach

I have a csv file. This is the format and info in a table.
PS C:\ $data | format-table
NAME PIP
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.
1 answer
Sort by: Most helpful
-
Rich Matheisen 39,261 Reputation points
2022-02-25T03:28:22.307+00:00