Author Posts

February 23, 2016 at 7:57 am

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 ! 🙂

February 23, 2016 at 8:25 am

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.

February 23, 2016 at 5:31 pm

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.

February 23, 2016 at 6:21 pm

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?

February 23, 2016 at 6:37 pm

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
}

February 24, 2016 at 12:17 am

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 !