I have 3 sets of array in Powershell

suggest change
$MachinesList  # Array 
$ResourceList # Array
$MachineTags  # Array

pseudo code 

$mongoDriverPath = 'C:\Program Files (x86)\MongoDB\CSharpDriver 1.7';
Add-Type -Path "$($mongoDriverPath)\MongoDB.Bson.dll";
Add-Type -Path "$($mongoDriverPath)\MongoDB.Driver.dll";

$db = [MongoDB.Driver.MongoDatabase]::Create('mongodb://127.0.0.1:2701/RGrpMachines');
[System.Collections.ArrayList]$TagList = $vm.tags 
$A1 = $Taglist.key
$A2 = $Taglist.value 
foreach ($Machine in $MachinesList) 
{
foreach($Resource in $ResourceList) 
{
            $doc2 = $null
           [MongoDB.Bson.BsonDocument] $doc2 = @{}; #Create a Document here 
            for($i = 0; $i -lt $TagList.count; $i++)
                   {
                        $A1Key = $A1[$i].ToString()
                        $A2Value = $A2[$i].toString()
                        $doc2.add("$A1Key", "$A2Value")
                   }
            
             [MongoDB.Bson.BsonDocument] $doc = @{
                "_id"= [MongoDB.Bson.ObjectId]::GenerateNewId();
                "ProcessTime"= [MongoDB.Bson.BsonDateTime] $ProcessTime;
                "LocalTime" = "$LocalTime";
                "Tags" = [MongoDB.Bson.BsonDocument] $doc2; 
                "ResourceGrp" = "$RGName"; 
                "HostName"= "$VMName";
                "Status"= "$VMStatus";
                "IPAddress"= "$IPAddress";
                "ResourceGroupName"= "$RGName";
                "SubscriptionName"= "$CurSubName";
                "SubscriptionID"= "$subid";
                "OS"= "$OSType";
            }; #doc loop close

            $collection.Insert($doc);
    }
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents