I'm attempting to create a custom object from an existing object. However, I can't seem to figure out the best way to go about doing this.
My goal is to create a custom object for each computer name that will have all of the values from Application Name.
I'm not sure if I should use a foreach or a where clause to make this happen and I'm also not sure the correct syntax to use either.
Thanks in advance for any help with this.
The data in the existing object looks like:
Computer Name, IP Address, Application Name
host1,10.10.10.10,firefox
host1,10.10.10.10,chrome
host1,10.10.10.10,internet explorer
host2,11.11.11.11,firefox
host2,11.11.11.11,chrome
host2,11.11.11.11,opera
Code Example:
foreach ($global:ComputerName in $global:SNWReportObject."Computer name"){
if ($_ -eq $global:ComputerName) {
Add-Member -InputObject $global:NEWReportObject -MemberType NoteProperty -Name ApplicationName -Value $global:SNWReportObject."Application name"
}
}
Results I'm hoping for:
Computer Name, Application Name
host1,firefox,chrome,internet explorer
host2,firefox,chrome,opera