Getting Data from XML

Welcome Forums General PowerShell Q&A Getting Data from XML

This topic contains 5 replies, has 4 voices, and was last updated by

3 years, 4 months ago.

  • Author
  • #35564

    Topics: 48
    Replies: 102
    Points: 0
    Rank: Member


    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:

    			Update for Microsoft SharePoint Designer 2010 (KB2553459) 64-Bit Edition

    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

    Topics: 9
    Replies: 2322
    Points: 0
    Rank: Member

    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

    Topics: 6
    Replies: 653
    Points: 20
    Rank: Member

    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

    Topics: 1
    Replies: 169
    Points: 0
    Rank: Member

    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

    Topics: 9
    Replies: 2322
    Points: 0
    Rank: Member

    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 :

    Function Get-CMSoftwareUpdatesFromUpdateGroup{
        $SofwareUpdateGroup = Get-CMSoftwareUpdateGroupAssignement -GroupName $GroupName
        $AssignedCIs = $SofwareUpdateGroup.AssignedCIs   
        $AllFoundUpdates = @()
        foreach ($Update in $AssignedCIs){
                [xml]$Ux = $Update
               $UpdateObj.Article = $ | Select-String -Pattern 'KB\d*' -AllMatches | % { $_.Matches } | % {$_.value}
               $ = $
               $UpdateObj.ModelName = $
               $UpdateObj.Version = $
               $UpdateObj.CIVersion = $
               $UpdateObj.ApplicabilityCondition = $
               $UpdateObj.EnforcementEnabled = $
               $UpdateObj.DisplayName = $
               $UpdateObj.UpdateClassification = $
            if ($UpdateObj -ne $null){
                $AllFoundUpdates += $UpdateObj
        }#end foreach
        return $AllFoundUpdates
  • #35609

    Topics: 48
    Replies: 102
    Points: 0
    Rank: Member

    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 !

The topic ‘Getting Data from XML’ is closed to new replies.