Author Posts

May 2, 2016 at 2:10 am

Hi,

I am having a bit of problems conceptualising how to produce a custom object that has multiple values in a property.

I am using these two variables

  $UpdateAssignment = Get-WmiObject -Query "Select * from CCM_AssignmentCompliance" -Namespace root\ccm\SoftwareUpdates\DeploymentAgent -Computer $computer -ErrorAction Stop
 $UpdateCIAssigment = Get-WmiObject -Query "SELECT * FROM CCM_UpdateCIAssignment" -Namespace "ROOT\ccm\policy\machine\Actualconfig" -ComputerName $computer -ErrorAction Stop

These are SCCM related information. I am particular interested in mixing up the property values of iscompliant in $updateassignment variable and assignmentname in $updateciassignment.

From my knowledge This will work all fine and dandy if there was one value but there are multiple values of these properties.

So I am getting an array within propertynames like this when I create an object:


Compliant    Software                                                                                                  
---------    --------                                                                                                  
{True, True} {Microsoft Software Updates - 2015-10-03 10:31:05 PM, Microsoft Software Updates - 2016-05-01 09:58:44 AM}

I thought creating another object with foreach might work but to no avail.

$icomplianceitem =@{}
foreach ($item in $Complianceobject){
$icomplianceitem = New-Object -TypeName psobject -Property @{
'Software' =$item.SoftwareName
'Compliant' =$item.Compliant
}

}

How would I iterate through the various items so I get a collection with seperate objects and not in an array.

Many thanks in advance.

May 2, 2016 at 4:43 am

The great thing about powershell is if you give it multiple values it will store multiple values. The bad thing about powershell is if you give it multiple values it will store multiple values. 🙂

In order to populate your object the way you want you must send it the data that way. Fortunately for you the data has a common key, the AssignmentID. using this you can query one and get the second piece of data that is linked.

 $UpdateAssignment = Get-WmiObject -Query "Select * from CCM_AssignmentCompliance" -Namespace root\ccm\SoftwareUpdates\DeploymentAgent -Computer $computer -ErrorAction Stop
 foreach($Assignment in $UpdateAssignment){
    $Assignment.AssignmentID
    $Assignment.IsCompliant
    $UpdateCIAssigment = Get-WmiObject -Query "SELECT * FROM CCM_UpdateCIAssignment where AssignmentID = '$($Assignment.AssignmentID)'" -Namespace "ROOT\ccm\policy\machine\Actualconfig" -ComputerName $computer -ErrorAction Stop
    $UpdateCIAssigment.assignmentname
 }

May 2, 2016 at 11:03 pm

Thanks Johnathan. Using your example as a template I was able to add objects to a collection. I think that was my problem. Many thanks.