From Task Sequence I need to have 2 informations in 2 different classes
public static readonly string TSPackageClassString = "SMS_TaskSequencePackage";
public static readonly string TSContainerItem = "SMS_ObjectContainerItem";
My WMI Query
string query = string.Format(CultureInfo.InvariantCulture,
"SELECT {0}.PackageID, {0}.Name, {0}.SecuredScopeNames, {0}.ObjectPath, {1}.ContainerNodeID " +
"FROM {0} INNER JOIN {1} ON {1}.InstanceKey = {0}.PackageID " +
"WHERE {1}.ObjectType = 20",
TSPackageClassString, TSContainerItem);
Run query
IResultObject listOfTaskSequences = connection.QueryProcessor.ExecuteQuery(query);
Enumerate through the collection of objects returned by the query
foreach (IResultObject TS in listOfTaskSequences)
{
MessageBox.Shox(TS.ToString());
}
The MessageBox
Screenshot
Then I don't find the way to browse results like that :
string packageID = TS["PackageID"].StringValue;
string folderID = TS["ContainerNodeID"].StringValue;
// or ...
string packageID = TS["SMS_TaskSequencePackage.PackageID"].StringValue;
string folderID = TS["SMS_ObjectContainerItem.ContainerNodeID"].StringValue;
Thanks for your help !
You would have to write it like this (needs a reference to System.Management for the System.Management.ManagementBaseObject):
using System.Management;
string folderID = ((ManagementBaseObject)TS["SMS_ObjectContainerItem"].ObjectValue)["ContainerNodeID"].ToString();
// or
ManagementBaseObject tsp = TS["SMS_TaskSequencePackage"].ObjectValue as ManagementBaseObject;
string packageID = tsp["PackageID"].ToString();
That being said imo the whole working with ManagementBaseObjects can be very unnecessary complex and annoying and WMI in general is slow, so if you have the possiblity to do the SCCM Queries in the DB directly instead of in the WMI DB you will get it faster, without strange intermediate DataTypes and also get the possiblity to use the much more powerful SQL over WQL