Sql query for gathering application and deployment information from SCCM/MECM

I am doing an application rationalization while in the process of merging two SCCM/MECM instances into one. This requires that I know what applications are packaged and deployed to either side, as well as, some additional useful information.
In the script below I am gathering All the applications that are currently deployed within my organization. You'll notice I commented out some of the lines of the script. This information will be split to go to different groups within my organization and some will just want application names whilst others may need to know the install/uninstall commands, and so on.
WITH XMLNAMESPACES ('http://schemas.microsoft.com/SystemsCenterConfigurationManager/2009/07/10/DesiredConfiguration' as desconfig,
DEFAULT 'http://schemas.microsoft.com/SystemCenterConfigurationManager/2009/AppMgmtDigest')
Select distinct
Apps.DisplayName,
DT.DisplayName AS [DeploymentTypeName],
DT.Technology
,fn.Name as [Location]
,PC.[Owner]
--,PC.[Support Contact]
--,PC.[Description]
--,Apps.NumberOfDeploymentTypes
--,Apps.HasContent
--,DT.PriorityInLatestApp
--,ISNULL(DT.SDMPackageDigest.value('(/AppMgmtDigest/DeploymentType/Installer/InstallAction/Args/Arg[@Name="Description"])[1]','nvarchar(MAX)'), 'None') AS [Decription]
--,ISNULL(DT.SDMPackageDigest.value('(/AppMgmtDigest/DeploymentType/Installer/InstallAction/Args/Arg[@Name="InstallCommandLine"])[1]','nvarchar(MAX)'), 'None') AS [InstallCommand]
--,ISNULL(DT.SDMPackageDigest.value('(/AppMgmtDigest/DeploymentType/Installer/UninstallAction/Args/Arg[@Name="InstallCommandLine"])[1]','nvarchar(MAX)'), 'None') AS [UninstallCommand]
,aa.CollectionName
,aa.AssignmentName
From fn_ListApplicationCIs(1033) Apps
Left Join fn_ListDeploymentTypeCIs(1033) DT ON DT.AppModelName = Apps.ModelName
Left join vFolderMembers fm on apps.ModelName = fm.InstanceKey
Left join vSMS_Folders fn on fm.ContainerNodeID = fn.ContainerNodeID
LEFT JOIN (
Select ISNULL(Apps.SDMPackageDigest.value('(/AppMgmtDigest/Application/DisplayInfo/Info/Description)[1]','nvarchar(MAX)'), 'None') AS [Description]
,Apps.SDMPackageDigest.value('(/AppMgmtDigest/Application/Owners/User/@Id)[1]', 'nvarchar(MAX)') [Owner]
,Apps.SDMPackageDigest.value('(/AppMgmtDigest/Application/Contacts/User/@Id)[1]', 'nvarchar(MAX)') [Support Contact]
,Apps.CI_ID from fn_ListApplicationCIs(1033) Apps ) AS [PC] ON PC.CI_ID = Apps.CI_ID
left join v_ApplicationAssignment aa on aa.ApplicationName = apps.DisplayName
Where Apps.IsLatest = 1 AND DT.IsLatest = 1 AND HasContent = 1 AND PriorityInLatestApp = 1 AND (fm.ObjectTypeName = N'SMS_ApplicationLatest' ) and aa.AssignmentName is not null
Download the Script...
SCCM
MECM
SQL
applications
inventory
Comments