I am trying to combine multiple object properties into one object.
When I have the following code the objects properties are combined.
$computer = gwmi win32_computersystem | select numberOfProcessors, NumberOfLogicalProcessors, HypervisorPresent
$osInfo = gwmi win32_operatingsystem | select version, caption, serialnumber, osarchitecture
Foreach($p in Get-Member -InputObject $osInfo -MemberType NoteProperty)
{
Add-Member -InputObject $computer -MemberType NoteProperty -Name $p.Name -Value $osInfo.$($p.Name) -Force
}
$computer
However, if I replace the above computer and osInfo variables with
$computer = Get-Process | Select processname, path
$osInfo = Get-Service | Select name, status
then the $computer variables does not have the properties of the $osInfo variable after the for loop is executed. ie: the second object is not combined with the first object.
$computerand$osInfoassignment of variables with the get-process and get-service respectively as shown above.