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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.