I was trying to filter the dataset that i got from SQL server database. Here is the scenario...
I'm getting servername,dbname columns from one of the database servers and returning the result set as return ,$dataSet.Tables[0]. I'm getting the results correctly in a table format.
But now i got all the server names to a variable from this dataset as below,
$servers=$dataSet_1.servername | select -unique
Now, i'm trying to loop through each server and get the database list associated to each server as follows, but looks like this is not a right approach as it is getting me all the severs and their database names is every iteration
foreach($server IN $servers)
{
write-host $server
$dataSet_1 | Where-Object {$dataSet_1.servername -eq $server} | select $_.dbname
}
Could someone help me the right approach are a way to do this.
Sample output: (Basically it should iterate each server and display its databasename)
ServerA
dbname
database1 database2 database3 ....
ServerB
dbname
database1 database8 database10 ....
ServerC ...
Thanks,