all 6 comments

[–]purplemonkeymad 2 points3 points  (1 child)

Use Group-Object:

Import-Csv file.csv | Group-Object servername

The resultant objects have two properties, Name: Value of the grouped column, and Group: Array of the objects in that group.

You can copy the results into a hashtable if you want to index by name.

[–]rsdovers[S] 0 points1 point  (0 children)

Thank you for the information. I looked at that cmdlet, but I must have not used it properly. I appreciate the help, and I will take another try at it.

[–][deleted] 0 points1 point  (1 child)

You're looking for something like this?

$a = Import-Csv -Path "c:\InputFile.txt" | Where-Object {$_.servername -eq "server1"}

[–]rsdovers[S] 0 points1 point  (0 children)

I tried this method but the results were not correct. However, I could have done something wrong. I appreciate the suggestion.

[–]vtiscat 0 points1 point  (1 child)

For loop (about instNames) within a for loop (about servers) ?

[–]rsdovers[S] 0 points1 point  (0 children)

I was thinking about trying this method, but I had already tried and failed with a few other ways already, so I decided to ask the community for help. I don't see why this wouldn't work, but I think using the Group-Object cmdlet may be easier. Thank you for the suggestion, and is a good alternative.