1

I'm trying to identify the location a task sequence sits using wmi so that I can only get particular task sequences that are stored in a particular sub folder.

For example in SCCM configuration manager under "Software Library>Overview>Operating Systems>Task Sequences" I have a folder called "LIVE" this is where task sequences I want to query sit. The problem I have is there are also a number of other folders that contain task sequences that I want to ignore (under "Task Sequences").

I can get all task sequences using

select * from SMS_TaskSequencePackage

but there is no location under any of the properties.

BDL
  • 21,052
  • 22
  • 49
  • 55
BillyDay
  • 37
  • 1
  • 4
  • 14

1 Answers1

2

I'm not good at writing C#, but we can surely using PowerShell and WMI query to get objects in a specific folder.

Before that, we need to know the ContainerNodeID of the specific folder first. There are plenty of ways to get it. For example, we use query:

$node = Get-WmiObject -Namespace ROOT\SMS\SITE_pri -class sms_objectcontainernode | Where-Object {$_.name -eq "folder1"}  
$nodeID = $node.containerNodeID

Then we can get all objects within this node by using below lines. The 20 is task sequence folder type.

$items = Get-WmiObject -Namespace root\sms\site_pri -Class sms_objectcontaineritem | Where-Object {$_.objectType -eq '20' -and $_.containerNodeID -eq $nodeID }  

Here we get all objects within Folder1. If we want to get all task sequence properties in this folder, we can add below:

$key = $items.instancekey
$tasksequences = Get-WmiObject -Namespace root\sms\site_pri -class sms_tasksequencepackage | Where-Object {$_.packageID -in $key}
$tasksequences

So all the full script is:(change the foldername and siteID)

$node = Get-WmiObject -Namespace ROOT\SMS\SITE_pri -class sms_objectcontainernode | Where-Object {$_.name -eq "folder1"} 
$nodeID = $node.containerNodeID
$items = Get-WmiObject -Namespace root\sms\site_pri -Class sms_objectcontaineritem | Where-Object {$_.objectType -eq '20' -and $_.containerNodeID -eq $nodeId }
$key = $items.instancekey
$tasksequences = Get-WmiObject -Namespace root\sms\site_pri -class sms_tasksequencepackage | Where-Object {$_.packageID -in $key}
$tasksequences
  • Thanks thats helped loads and ive managed to target only the task sequences i need. By getting the IDs from querying sms_objectcontainernode and sms_objectcontaineritem i was then able to get the PackageIds. – BillyDay Apr 19 '17 at 10:21