Because of the workload and limited time to post on my personal blog, I’ve decided to do small little posts like this when I talk about different challenges that I personally, or some other colleagues in the industry faced during their working days.
Today I want to have a look over the SDMPackageXML object that the Get-CMApplication PowerShell cmdlet for SCCM is outputting. Of course, lots of information is already available in the resulting objects of the cmdlet, but what if you want to export a list of applications with their Install Command Line, the location of the sources and Title of the application?
If we have a look over the SDMPackageXML we can see that it’s obvious (even from it’s name) that the output is an XML, so we can use the parser from PowerShell to do what we said earlier. The code is:
$Applications = Get-CMApplication -name “K*”
$Outfile = “\\someShare\example\”
ForEach($Element in $Applications)
{
$csv = New-object psobject -property @{
‘Commandline’ = (($Element.SDMPackageXML)).AppMgmtDigest.DeploymentType.Installer.CustomData.InstallCommandLine
‘Version’ = $Element.SoftwareVersion
‘Location’ = (($Element.SDMPackageXML)).AppMgmtDigest.DeploymentType.Installer.Contents.Content.Location
‘DisplayNameSCCM’ = $Element.LocalizedDisplayName
‘Title’ = (($Element.SDMPackageXML)).AppMgmtDigest.Application.DisplayInfo.Info.Title
}
$csv | select-object ‘DisplayNameSCCM’,’Title’,’Version’,’Location’,’Commandline’ | Export-csv -Append -path (‘FileSystem::’ + $Outfile)
}
What is the code doing?
- $Applications = Get-CMApplication -name “K*” > I am getting all the applications which the name starts with K
- ForEach($Element in $Applications) > Parsing the resulting elements
- $csv = New-object psobject -property @{ > We create a new object in order to output a CSV with all the information
- ‘Commandline’ = (($Element.SDMPackageXML)).AppMgmtDigest.DeploymentType.Installer.CustomData.InstallCommandLine > This is how we parse the Install Command line. We do the same for the other desired elements in the XML
- $csv | select-object ‘DisplayNameSCCM’,’Title’,’Version’,’Location’,’Commandline’ | Export-csv -Append -path (‘FileSystem::’ + $Outfile) > We build and append to the CSV the resulting information from the above objects.
Basically, with the [XML] parser, you need to select the particular node that you want to get the information from. If you don’t know exactly where that is you can just simply test something like this:
$Application = Get-CMApplication -name “Kaspersky”
$Commandline = (($Application.SDMPackageXML)).AppMgmtDigest.DeploymentType.Installer.CustomData.InstallCommandLine
Write-host $Commandline