Answered by:
Powershell scrpt to list apps in a folder

-
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
Question
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 9, 2015 6:55 AM
- Marked as answer by Kishore.au Wednesday, December 9, 2015 6:55 AM
- Unmarked as answer by Kishore.au Wednesday, December 9, 2015 6:55 AM
- Marked as answer by Kishore.au Wednesday, December 9, 2015 6:55 AM
All replies
-
This should get you started with something that's a bit faster: http://blog.coretech.dk/kaj/the-easy-way-list-objects-in-specific-folder-in-configuration-manager-2012-with-powershell/
My Blog: http://www.petervanderwoude.nl/
Follow me on twitter: pvanderwoude- Proposed as answer by Jason SandysMVP, Moderator Monday, December 7, 2015 12:54 PM
-
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 9, 2015 6:55 AM
- Marked as answer by Kishore.au Wednesday, December 9, 2015 6:55 AM
- Unmarked as answer by Kishore.au Wednesday, December 9, 2015 6:55 AM
- Marked as answer by Kishore.au Wednesday, December 9, 2015 6:55 AM
-
-
I have that code as an accepted solution everywhere but I get 'generic failure' message when I run the code
Nigel
Garth Jones
Blog: https://www.enhansoft.com/blog Old Blog: http://smsug.ca/blogs/garth_jones/default.aspx
Twitter: @GarthMJ Book: System Center Configuration Manager Reporting Unleashed