Problems coceptualising Multiple layers of values in property in object and prod

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Wei-Yen Tan Wei-Yen Tan 7 months ago.

  • Author
    Posts
  • #38471
    Profile photo of Wei-Yen Tan
    Wei-Yen Tan
    Participant

    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.

  • #38474
    Profile photo of Jonathan Warnken
    Jonathan Warnken
    Participant

    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
     }
    
    
  • #38506
    Profile photo of Wei-Yen Tan
    Wei-Yen Tan
    Participant

    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.

You must be logged in to reply to this topic.