Create a Tree View of Applications and Dependencies

Here’s a quick code to get a tree view (sort of) of applications in your ConfigMgr 2012 environment that shows dependencies, including dependencies of dependencies. Works as is, for me at least. If you spot any bugs or improvements feel free to let me know. As usual watch out for word-wrapping and typos.

Function Get-Dependency($appCIID,$appNameFunc){

gwmi -ComputerName $server -Namespace “root\sms\site_$code -Class SMS_AppDependenceRelation -Filter “FromApplicationCIID=’$appCIID | %{

if($_.ToApplicationCIID -ne $null){

$ToApplicationCIID = $_.ToApplicationCIID

$dependencyName = Resolve-ApplicationName $ToApplicationCIID    

$dependencyNameSub = ” –>$dependencyName

Write-Host $dependencyNameSub     

Get-SubDependency $ToApplicationCIID $dependencyNameSub   

}

 }

return

}

Function Get-SubDependency($appCIID, $appNameFunc){

$appNamePrefix = ” “ + ($appNameFunc -split “>”)[0] + “>”

gwmi -ComputerName $server -Namespace “root\sms\site_$code -Class SMS_AppDependenceRelation -Filter “FromApplicationCIID=’$appCIID | %{

if($_.ToApplicationCIID -ne $null){

$ToApplicationCIID = $_.ToApplicationCIID

$dependencyName = Resolve-ApplicationName $ToApplicationCIID   

$dependencyName =$appNamePrefix$dependencyName

Write-Host$dependencyName

Get-SubDependency $ToApplicationCIID $dependencyName   

}

}

return

}

Function Resolve-ApplicationName($appCIID){

gwmi -ComputerName $server -Namespace “root\sms\site_$code -Class SMS_ApplicationLatest -Filter “CI_ID = ‘$appCIID‘” | select LocalizedDisplayName | %{

return $_.LocalizedDisplayName

}

}

cls

$server = “serverName”

$code = “001”

gwmi -ComputerName $server -Namespace “root\sms\site_$code -Class SMS_ApplicationLatest | %{

$appName = $_.LocalizedDisplayName

$CIID = $_.CI_ID

Write-Host$appName

Get-Dependency $CIID $appName

}

Advertisements

9 thoughts on “Create a Tree View of Applications and Dependencies

  1. watson49 August 12, 2015 / 12:12 pm

    Sounds grate but cant get it too work for me.
    Please can you show me all the parameters I need to change for my Site.
    Not grate at this sort of thing.
    Thank you.

    • andrewdcraig August 12, 2015 / 12:21 pm

      you need to specify the SCCM Server with the $server variable, and the sitecode in $code. That’s all. if you get an error it’s probably a font/copy/paste problem.

      • watson49 August 12, 2015 / 4:19 pm

        Thanks will Double check the copy and paste and give it a try.
        1 Last thing, does it export to file or is it a on screen display only.

      • watson49 August 12, 2015 / 4:26 pm

        Im getting error
        gwmi : Generic failure
        At line:2 char:1
        + gwmi -ComputerName $server -Namespace “root\sms\site_$code” -Class SMS_AppDepend …
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException
        + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

        I did change following as you suggested.

        $server = “serverName”
        $code = “001”

        Thanks a lot by the way.

  2. watson49 August 12, 2015 / 6:28 pm

    Found the problem
    Had to do a find and replace for the ‘ & “ as they don’t copy correctly.

    Any quick way to PIPE it to CSV so It can be sorted/Filtered.

    • andrewdcraig August 18, 2015 / 2:22 pm

      Hi, i got caught up in work, sorry. So it works now for you? I don’t think piping to a csv would work because of the Format of the Output. Probbly a better way then would be to create an XML document and write the top Level apps as nodes, then write subnodes for the dependencies… As is, is just a command window Output view.

  3. Lieven August 20, 2015 / 11:04 am

    Nice work Andrew. Just a question/addition:
    How to check dependencies (and dependencies of dependencies) for a single application? What variabele can be used for that?
    E.g. I want all the dependencies (and dep. of dep.) of ‘Microsoft Office 2010’?

    Thanks

    • andrewdcraig August 24, 2015 / 2:42 pm

      at the top of the script add this:
      Param($inAppName=”ALL”)

      then replace this line:
      gwmi -ComputerName $server -Namespace “root\sms\site_$code” -Class SMS_ApplicationLatest | %{
      with:
      gwmi -ComputerName $server -Namespace “root\sms\site_$code” -Class SMS_ApplicationLatest | ?{$_.LocalizedDisplayName -like “*$inAppName*” -or $inAppName -eq ‘ALL’} | %{

      then you can run the script with a Parameter for a specific application, or even a Wildcard.

  4. Donga December 19, 2017 / 5:42 am

    Anyone checked out the SMS_AppDependenceRelation_Flat class in particular to is level property 😉

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s