Getting Data from XML

This topic contains 5 replies, has 4 voices, and was last updated by Profile photo of Graham Beer Graham Beer 9 months, 2 weeks ago.

  • Author
    Posts
  • #35564
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Hi,

    I'm trying through WMI to get some software update information from the SCCM namespace. When i create the variable of $run through the below code, the area i'm interested in is "AssignedCIs". This is displayed in a XML format.

    $Query = @{
    Namespace = 'root\ccm\policy\machine\actualconfig'
    ClassName = 'CCM_UpdateCIAssignment'
    }
    
    $run = Get-CimInstance @query
    
    $xml = $run.assignedCIs | ConvertTo-Xml -NoTypeInformation
    

    So i convert the results as XML.

    Here is what it looks like:

    
    		
    			57d58fbe-1fcf-4a8e-80e2-f4879ed802df
    			Site_47A3BB0F-C21F-4658-926A-67657D06EC0B/SUM_57d58fbe-1fcf-4a8e-80e2-f4879ed802df
    			1.00
    			200
    			
    				57d58fbe-1fcf-4a8e-80e2-f4879ed802df{47A3BB0F-C21F-4658-926A-67657D06EC0B}1384f5f325-30d7-41c4-81d1-87a0e6535
    b66
    			
    			FALSE
    			Update for Microsoft SharePoint Designer 2010 (KB2553459) 64-Bit Edition
    			e6cf1350-c01b-414d-a61f-263d14d133b4
    		
    

    I want to pull out the Displayname details to start with. But i can't seem to get it right.

    If i use the XML created variable, $XML.Objects.Object i can't select the displayname 'field'. It also puts the Objects.object into a system.string but step up to $XML.Objects and its an XMLElement. Could really do with some guidance please ! 🙂

  • #35566
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    You'll need to create a gist with your XML stuff; our forum software treats it all like HTML tags and screws with the formatting.

  • #35595
    Profile photo of Curtis Smith
    Curtis Smith
    Participant

    Just curious, what is the CIM call to SCCM returning? If it's a normal object, why not just get the data from it? Why convert it to XML first? I don't have an SCCM environment so I can't test.

  • #35598
    Profile photo of Jonathan Warnken
    Jonathan Warnken
    Participant

    The problem is the way the info is stored in wmi. It is a big string with several xml "declarations"

    While it is possible to parse through it, I would ask if the information you want is somewhere else?

  • #35601
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    ConvertTo-Xml isn't what you're after; that's for taking an object and making an XML representation of it, not the other way around. Instead, you'd just be taking a string and casting it to the [xml] type. Here's an example of what that might look like, from http://powershelldistrict.com/missing-software-updates-powershell/ :

    Function Get-CMSoftwareUpdatesFromUpdateGroup{
        Param(
            [Parameter(Mandatory=$true)]$GroupName
        )
        $SofwareUpdateGroup = Get-CMSoftwareUpdateGroupAssignement -GroupName $GroupName
        $AssignedCIs = $SofwareUpdateGroup.AssignedCIs   
    
        $AllFoundUpdates = @()
        foreach ($Update in $AssignedCIs){
           
           $UpdateObj=[pscustomobject]@{"Article"="";"Id"="";"ModelName"="";"Version"="";"CIVersion"="";"ApplicabilityCondition"="";"EnforcementEnabled"="";"DisplayName"="";"UpdateClassification"=""}
                [xml]$Ux = $Update
               $UpdateObj.Article = $Ux.ci.DisplayName | Select-String -Pattern 'KB\d*' -AllMatches | % { $_.Matches } | % {$_.value}
               $UpdateObj.id = $ux.ci.id
               $UpdateObj.ModelName = $Ux.ci.ModelName
               $UpdateObj.Version = $ux.ci.version
               $UpdateObj.CIVersion = $ux.ci.civersion
               $UpdateObj.ApplicabilityCondition = $ux.ci.ApplicabilityCondition
               $UpdateObj.EnforcementEnabled = $ux.ci.EnforcementEnabled
               $UpdateObj.DisplayName = $Ux.ci.DisplayName
               $UpdateObj.UpdateClassification = $ux.ci.UpdateClassification
    
            if ($UpdateObj -ne $null){
                $AllFoundUpdates += $UpdateObj
            }
            
        }#end foreach
    
        return $AllFoundUpdates
    }
    
  • #35609
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Thank you all, i will go back to it this morning.
    Thank you Dave, i'll have a play with what you've done. A useful peace of code and usage Dave, will help my learning !

You must be logged in to reply to this topic.