Output at the same time on the one line, some properties of the two objects

Posted on 2013-09-22
Medium Priority
Last Modified: 2013-09-23
I have two objects, both have a  same property -"Name" .

 $GenItems1 = gwmi Win32_ComputerSystem -Comp $StrComputer

 $GenItems2 = gwmi Win32_OperatingSystem -Comp $strComputer

How can I output at the same time on the one line, some properties of the two objects ?
Question by:nesher13
  • 2
LVL 42

Expert Comment

ID: 39513320
You just need to build an object with custom properties.
Here's a couple methods.
"" | Select @{N="Computer";E={$GenItems1.Name}},@{N="OS";E={$GenItems2.Name}}
New-Object PSObject -property @{ Computer = $GenItems1.Name; OS = $GenItems2.Name}

Open in new window


Author Comment

ID: 39513985
Hi footech,

which means " in the pipeline
LVL 42

Accepted Solution

footech earned 2000 total points
ID: 39515124
I assume you're asking about the first method.  There we're sending an empty object through the pipeline to Select-Object which we use to create calculated properties (i.e. the property is not chosen from the properties associated with the object sent to Select-Object, but rather is calculated based on other information).

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

The PowerShell Core 6.0 of .NET release is just the beginning. The upcoming PowerShell Core 6.1 would have artificial intelligence and internet of things capabilities. So many things to look forward to in the upcoming release.
Seizing the Operation Master Roles in Windows Server 2016 in case of FSMO holder failure.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question