none
Powershell scrpt to list apps in a folder

    Question

  • Hi,

    I am trying to generate a powershell script which can list the applications in a folder in sccm 2012 .  we keep the applications in different folders for our convenience like packaging team will keep their apps in folder while they are working and it will be moved to differnet folders during the application life cycle.

    Is there any power shell functions which i can use to achieve this ?

    Below code gives me the applications in "PROD" folder. But i think querying all apps and then getting the folder is not a good way of doing it ?

    ## Get all the applications available in SCCM
    $apps =  Get-WmiObject -ComputerName $SiteServer -Namespace root\SMS\site_$SiteCode -class SMS_Applicationlatest
     


     ## Loop through all the apps
     foreach ($app in $apps)
     {

        $instancekey = $app.ModelName ## This is the CI Unique ID from which we can get the application container folder using below Query
        $ContainerNode = Get-WmiObject -Namespace root/SMS/site_$($SiteCode) -ComputerName $SiteServer -Query "SELECT ocn.* FROM SMS_ObjectContainerNode AS ocn JOIN SMS_ObjectContainerItem AS oci ON ocn.ContainerNodeID=oci.ContainerNodeID WHERE oci.InstanceKey='$InstanceKey'"
     
     
            if ($ContainerNode -ne $null)

                {
                    $ObjectFolder = $ContainerNode.Name
              
                     ## Ignore the folder if its not PROD

                    if ($ObjectFolder -eq 'PROD')
                     {
                     Echo $app.LocalizedDisplayName  ## Print the application name
                     }
                }

      }

    Thanks for the help...

    Kishore


    Kishore

    Monday, December 07, 2015 5:45 AM

Answers

  • Thanks for the direction Peter, I figured it out

    $FolderID = XXXXXXX
    $Instancekeys = (Get-WmiObject -Namespace "ROOT\SMS\Site_CMT" -query "select InstanceKey from SMS_ObjectContainerItem where ObjectType='6000' and  ContainerNodeID='$FolderID'").instanceKey
    foreach ($key in $Instancekeys)
    {
    (Get-WmiObject -Namespace "ROOT\SMS\Site_XXX" -Query "select * from SMS_Applicationlatest  where ModelName = '$key'").LocalizedDisplayName
    }

    • Edited by Kishore.au Wednesday, December 09, 2015 6:55 AM
    • Marked as answer by Kishore.au Wednesday, December 09, 2015 6:55 AM
    • Unmarked as answer by Kishore.au Wednesday, December 09, 2015 6:55 AM
    • Marked as answer by Kishore.au Wednesday, December 09, 2015 6:55 AM
    Wednesday, December 09, 2015 6:54 AM

All replies