1

I would like to combine the result of 2 tables into 1 A and B :

$A = Invoke-Command -ScriptBlock { get-wmiobject Win32_Product  |  where-Object{ $_.name -like "*Google*" } | select PackageName ,PSComputerName  }
$B = gwmi win32_operatingsystem | select osarchitecture ,PSComputerName

Result A :

PackageName                            PSComputerName
-----------                            --------------
googlechromestandaloneenterprise64.msi COMPUTER1  

Result B :

osarchitecture PSComputerName
-------------- --------------
64-bit         COMPUTER1  

The desired output :

PackageName                            PSComputerName      osarchitecture
-----------                            --------------      --------------
googlechromestandaloneenterprise64.msi COMPUTER1           64-bit

Thanks in advance

Olaf
  • 4,690
  • 2
  • 15
  • 23
OussLa
  • 13
  • 4
  • 1
    You could use a `[PSCustomObject]`. – Olaf Mar 17 '21 at 10:29
  • Using this [`Join-Object`](https://www.powershellgallery.com/packages/Join) cmdlet (see also: [In Powershell, what's the best way to join two tables into one?](https://stackoverflow.com/a/45483110/1701026)): `$a |Join $b -on PSComputerName` – iRon Mar 17 '21 at 14:27
  • your 2nd line is getting info from the LOCAL system. why don't you put both calls into one `Invoke-Command` call? – Lee_Dailey Mar 17 '21 at 21:31

1 Answers1

0

There are a couple of ways to do this, two of them shown below:

Using Select-Object

Using Select-Object, we can create a new object by stitching the output from one command onto the output from another:

$OSArch = (Get-WmiObject Win32_OperatingSystem).OSArchitecture
Get-WmiObject Win32_Product |Where-Object Name -like "*Google*" |Select-Object PackageName,@{Name='OSArchitecture';Expression={$OSArch}},PSComputerName

Create a [pscustomobject]

Another popular option is by using the [pscustomobject] syntax introduced in PowerShell 3.0:

$OSArch = (Get-WmiObject Win32_OperatingSystem).OSArchitecture
Get-WmiObject Win32_Product |Where-Object Name -like "*Google*" |ForEach-Object {
    [pscustomobject]@{
        PackageName = $_.PackageName
        OSArchitecture = $OSArch
        PSComputerName = $_.PSComputerName
    }
}
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206