# Trying to combine 3 variables for elegant looking output

**URL:** <https://forums.powershell.org/t/trying-to-combine-3-variables-for-elegant-looking-output/21351>\
**Category:** PowerShell Help\
**Created:** [January 12, 2023, 2:42pm UTC](https://forums.powershell.org/t/trying-to-combine-3-variables-for-elegant-looking-output/21351 "2023-01-12T14:42:21Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [January 12, 2023, 3:22pm UTC](https://forums.powershell.org/t/trying-to-combine-3-variables-for-elegant-looking-output/21351/2 "2023-01-12T15:22:10Z")

</div>

Usually we use loops or nested loops in combination with a `PSCustomObject` to combine the results from different but related queries.

Here’s an example of how to combine the results of 3 different sources in one output object:

```auto
$ComputerName = 'DesiredRemoteComputer'

$so = New-CimSessionOption -Protocol DCOM 
$CimSession = New-CimSession -CN $ComputerName -SessionOption $so
$BIOS = Get-CimInstance -Class CIM_BIOSElement -CimSession $CimSession | Select-Object -Property *
$OS = Get-CimInstance -Class CIM_OperatingSystem -CimSession $CimSession | Select-Object -Property *
$Computer = Get-CimInstance -Class CIM_ComputerSystem -CimSession $CimSession | Select-Object -Property *
[PSCustomObject]@{
    ComputerName = $BIOS.PSComputerName;
    Model = $Computer.Model;
    BIOSName = $BIOS.Name;
    SMBIOSVersion = $BIOS.SMBIOSBIOSVersion;
    BIOSVersion = $BIOS.BIOSVersion;
    ReleaseDate = $BIOS.ReleaseDate;
    SerialNumber = $BIOS.SerialNumber;
    OSCaption = $OS.Caption;
    OSVersion = $OS.Version;
    InstallDate = $OS.InstallDate;
    LastBootUpTime = $OS.LastBootUpTime;
    PhysicalRAM = [math]::round((($Computer.TotalPhysicalMemory) / 1GB), 2);
}

```

If one of this queries results in an array you’d need to add a loop and iterate over its elements. The `[PSCustomObject]` is always created inside the inner most loop if you have nested loops.

---

_[View the full topic](https://forums.powershell.org/t/trying-to-combine-3-variables-for-elegant-looking-output/21351)._
