Getting Data from XML


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 ! :slight_smile:

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.

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.

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?

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

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 !