locked
How to advertise task sequence? RRS feed

  • Question

  • I didn't find it in SDK. Would you please help me with an example?
    Monday, August 24, 2009 11:26 AM

Answers

  • If it's a task sequence for distributing software, just think of the Task Sequence as a regular package with a PackageID. Create a Collection and an Advertisement to connect the Package and Collection.  When you add computers to the Collection they should recieve the TaskSequence advertisement.

    I haven't made any Task Sequences for distributing OS myself, but the advertisement process ain't different from the above.


    Create Advertisement:
    connectionManager = connection.Connect();
    IResultObject newAdvertisement = connectionManager.CreateInstance("SMS_Advertisement");
    
    newAdvertisement["CollectionID"].StringValue = TScollection;
    newAdvertisement["PackageID"].StringValue = TSPackageID;
    newAdvertisement["ProgramName"].StringValue = "*";
    newAdvertisement["AdvertisementName"].StringValue = "AdvertisementName";
    newAdvertisement["Comment"].StringValue = "AdvertisementComment";
    newAdvertisement["AdvertFlags"].LongValue = 42074112;
    newAdvertisement["RemoteClientFlags"].LongValue = 4384;
    newAdvertisement.Put();
    
    connectionManager.Dispose();
    connectionManager.Close();

    Add computer to Collection:
            public bool CreateDirectRule(string collectionID, string resourceClassName, UInt32 resourceID)
            {
                try
                {
                    connectionManager = connection.Connect();
                    IResultObject collection = connectionManager.GetInstance(@"SMS_Collection.CollectionID='" + collectionID + "'");
    
                    IResultObject newStaticRule = connectionManager.CreateInstance("SMS_CollectionRuleDirect");
                    newStaticRule["ResourceClassName"].StringValue = resourceClassName;
                    newStaticRule["ResourceID"].LongValue = resourceID;
                    newStaticRule["RuleName"].StringValue = Query.GetComputerByID(resourceID.ToString());
    
                    Dictionary<string, object> addMembershipRuleParameters = new Dictionary<string, object>();
                    addMembershipRuleParameters.Add("collectionRule", newStaticRule);
                    IResultObject staticID = collection.ExecuteMethod("AddMembershipRule", addMembershipRuleParameters);
    
                    Dictionary<string, object> requestRefreshParameters = new Dictionary<string, object>();
                    requestRefreshParameters.Add("IncludeSubCollections", false);
                    collection.ExecuteMethod("RequestRefresh", requestRefreshParameters);
                    return true;
                }
                catch (SmsException e)
                {
                    //throw new Exception("Failed to create collection membership. Error: " + e.Message);
                    return false;
                }
                finally
                {
                    connectionManager.Dispose();
                    connectionManager.Close();
                }
            }
    

    Thursday, September 10, 2009 11:03 AM

All replies

  • Not an example, but this has the details:

    http://msdn.microsoft.com/en-us/library/cc143278.aspx

    Task Sequence Packages

    A task sequence is packaged in an instance of the SMS_TaskSequencePackage Server WMI Class class and there is a single package for each task sequence. The package is advertised to client computers by using an instance of the SMS_Advertisement Server WMI Class class. To associate the task sequence package with the advertisement, you set the SMS_Advertisement Server WMI Class PackageID property to the SMS_TaskSequencePackage Server WMI Class PackageID property.

    note Note
    SMS_TaskSequencePackage Server WMI Class derives from SMS_Package Server WMI Class and can be used in the same way that packages are used. For more information, see Software Distribution Packages .

    For more information about creating a task sequence package, see How to Create an Operating System Deployment Task Sequence Package .

    For more information about creating advertisements, see How to Create an Advertisement .

    Monday, August 24, 2009 2:48 PM
  • If it's a task sequence for distributing software, just think of the Task Sequence as a regular package with a PackageID. Create a Collection and an Advertisement to connect the Package and Collection.  When you add computers to the Collection they should recieve the TaskSequence advertisement.

    I haven't made any Task Sequences for distributing OS myself, but the advertisement process ain't different from the above.


    Create Advertisement:
    connectionManager = connection.Connect();
    IResultObject newAdvertisement = connectionManager.CreateInstance("SMS_Advertisement");
    
    newAdvertisement["CollectionID"].StringValue = TScollection;
    newAdvertisement["PackageID"].StringValue = TSPackageID;
    newAdvertisement["ProgramName"].StringValue = "*";
    newAdvertisement["AdvertisementName"].StringValue = "AdvertisementName";
    newAdvertisement["Comment"].StringValue = "AdvertisementComment";
    newAdvertisement["AdvertFlags"].LongValue = 42074112;
    newAdvertisement["RemoteClientFlags"].LongValue = 4384;
    newAdvertisement.Put();
    
    connectionManager.Dispose();
    connectionManager.Close();

    Add computer to Collection:
            public bool CreateDirectRule(string collectionID, string resourceClassName, UInt32 resourceID)
            {
                try
                {
                    connectionManager = connection.Connect();
                    IResultObject collection = connectionManager.GetInstance(@"SMS_Collection.CollectionID='" + collectionID + "'");
    
                    IResultObject newStaticRule = connectionManager.CreateInstance("SMS_CollectionRuleDirect");
                    newStaticRule["ResourceClassName"].StringValue = resourceClassName;
                    newStaticRule["ResourceID"].LongValue = resourceID;
                    newStaticRule["RuleName"].StringValue = Query.GetComputerByID(resourceID.ToString());
    
                    Dictionary<string, object> addMembershipRuleParameters = new Dictionary<string, object>();
                    addMembershipRuleParameters.Add("collectionRule", newStaticRule);
                    IResultObject staticID = collection.ExecuteMethod("AddMembershipRule", addMembershipRuleParameters);
    
                    Dictionary<string, object> requestRefreshParameters = new Dictionary<string, object>();
                    requestRefreshParameters.Add("IncludeSubCollections", false);
                    collection.ExecuteMethod("RequestRefresh", requestRefreshParameters);
                    return true;
                }
                catch (SmsException e)
                {
                    //throw new Exception("Failed to create collection membership. Error: " + e.Message);
                    return false;
                }
                finally
                {
                    connectionManager.Dispose();
                    connectionManager.Close();
                }
            }
    

    Thursday, September 10, 2009 11:03 AM