Combining 2 PSObjects in Powershell

Viewed 25

Below is the code I am writing and facing some difficulty getting the objects joined . Please help me on that. Though I used array += , only one object is getting resulted out . Please help me get corrected.

$array = @()
$DC1Ser = Get-Content -Path C:\temp\DC1ServersListMain.txt
$DC1 = foreach($ls in $DC1Ser){
Get-WmiObject -ComputerName $ls -Class Win32_logicaldisk -Filter "DriveType = '3'" | `
?{$_.DeviceID -like "U:"} |`
Select @{l='HostName';e={$ls}}, @{l="DC1UFreeGB";e={"{0:N2}" -f ($_.FreeSpace/1GB)}}
}

$DC2Ser = Get-Content -Path c:\temp\DC2ServerListMain.txt
$DC2 = foreach($ts in $DC2Ser){
Get-ChildItem -Path "\\$ts\U$\DL" | Measure-Object -Property Length -Sum |`
select  @{l='HostName';e={$ts}},@{label = "DLSizeGB";e= {"{0:N2}" -f ($_.sum/1GB)}} 
}

 foreach($i in $DC2){
 $array  += [PSCustomObject]@{ 
 DC2Host  = $i.HostName   
 DLSizeGB = $i.DLSizeGB
 }
 }
 foreach($e in $DC1){

 $array  += [PSCustomObject]@{ 
    DC1Host     = $e.HostName
    DC1UFreeGB  = $e.DC1UFreeGB
 }

 }
 $array
0 Answers
Related