简体   繁体   English

使用wmi c#获取SCCM 2012任务序列的位置

[英]Get Location of SCCM 2012 Task Sequence using wmi c#

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. 我正在尝试使用wmi识别任务序列所在的位置,以便只能获取存储在特定子文件夹中的特定任务序列。

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. 例如,在SCCM配置管理器中的“软件库>概述>操作系统>任务序列”下,我有一个名为“ LIVE”的文件夹,这是我要查询的任务序列所在的位置。 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. 我不太擅长编写C#,但是我们可以肯定地使用PowerShell和WMI查询来获取特定文件夹中的对象。

Before that, we need to know the ContainerNodeID of the specific folder first. 在此之前,我们需要首先知道特定文件夹的ContainerNodeID 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. 20是任务序列文件夹类型。

$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. 在这里,我们得到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) 所以所有的完整脚本是:(更改文件夹名称和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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM