I am trying to add a number to the end of a variable to use in a for loop. I have imported a csv with Import-Csv into a variable called $csvImport which contains 8 items referenced as csvImport.disk1, csvImport.disk2 and so on up to disk8.
I am trying to increment the number at the end of disk so that I don't have to use 8 if statements. Here is my code:
for ($i = 1; $i -lt 9; $i++)
{
if ($csvImport.disk"$i" -ne "")
{
do stuff
}
}
The code is wrong but I'm looking for some advice on how I can achieve having $csvImport.disk"$i" return $csvImport.disk1, $csvImport.disk2 and so on in the loop.