How to create a deployment

The following examples show how to create a Configuration Manager deployment with the SMS_Advertisement class and its properties.


The account that creates the deployment needs the Deploy Packages permission for the collection and Read permission for the package.


  1. Set up a connection to the SMS Provider.

  2. Create a new object of the SMS_Advertisement class.

  3. Populate the new advertisement properties.

  4. Save the new advertisement and properties.


The following examples create an advertisement for software distribution.

For more information about calling the sample code, see Calling Configuration Manager code snippets.

Sub SWDCreateAdvertisement(connection, existingCollectionID, existingPackageID, existingProgramName, newAdvertisementName, newAdvertisementComment, newAdvertisementFlags, newRemoteClientFlags, newAdvertisementStartOfferDateTime, newAdvertisementStartOfferEnabled)  
    Dim newAdvertisement  
    ' Create the new advertisement object.  
    Set newAdvertisement = connection.Get("SMS_Advertisement").SpawnInstance_  

    ' Populate the advertisement properties.  
    newAdvertisement.CollectionID = existingCollectionID  
    newAdvertisement.PackageID = existingPackageID  
    newAdvertisement.ProgramName = existingProgramName  
    newAdvertisement.AdvertisementName = newAdvertisementName  
    newAdvertisement.Comment = newAdvertisementComment  
    newAdvertisement.AdvertFlags = newAdvertisementFlags  
    newAdvertisement.RemoteClientFlags = newRemoteClientFlags
    newAdvertisement.PresentTime = newAdvertisementStartOfferDateTime  
    newAdvertisement.PresentTimeEnabled = newAdvertisementStartOfferEnabled  

    ' Save the new advertisement and properties.  

    ' Output new advertisement name.  
    Wscript.Echo "Created advertisement: " & newAdvertisement.AdvertisementName  

End Sub  
public void CreateSWDAdvertisement(WqlConnectionManager connection, string existingCollectionID, string existingPackageID, string existingProgramName, string newAdvertisementName, string newAdvertisementComment, int newAdvertisementFlags, int newRemoteClientFlags, string newAdvertisementStartOfferDateTime, bool newAdvertisementStartOfferEnabled)  
        // Create new advertisement instance.  
        IResultObject newAdvertisement = connection.CreateInstance("SMS_Advertisement");  

        // Populate new advertisement values.  
        newAdvertisement["CollectionID"].StringValue = existingCollectionID;  
        newAdvertisement["PackageID"].StringValue = existingPackageID;  
        newAdvertisement["ProgramName"].StringValue = existingProgramName;  
        newAdvertisement["AdvertisementName"].StringValue = newAdvertisementName;  
        newAdvertisement["Comment"].StringValue = newAdvertisementComment;  
        newAdvertisement["AdvertFlags"].IntegerValue = newAdvertisementFlags;  
        newAdvertisement["RemoteClientFlag"].IntegerValue = newRemoteClientFlags;
        newAdvertisement["PresentTime"].StringValue = newAdvertisementStartOfferDateTime;  
        newAdvertisement["PresentTimeEnabled"].BooleanValue = newAdvertisementStartOfferEnabled;  

        // Save the new advertisement and properties.  

        // Output new assignment name.  
        Console.WriteLine("Created advertisement: " + newAdvertisement["AdvertisementName"].StringValue);  

    catch (SmsException ex)  
        Console.WriteLine("Failed to assign advertisement. Error: " + ex.Message);  

The example method has the following parameters:

Parameter Type Description

- Managed: WqlConnectionManager
- VBScript: SWbemServices
A valid connection to the SMS Provider.
existingCollectionID String The ID of an existing collection with which to associate the advertisement.
existingPackageID String The ID of an existing package with which to associate the advertisement.
existingProgramName String The name for the program associated with the advertisement.
newAdvertisementName String The name for the new advertisement.
newAdvertisementComment String A comment for the new advertisement.
newAdvertisementFlags Integer Flags specifying options for the new advertisement.
newRemoteClientFlags Integer Flags specifying how the program should run when the client connects either locally or remotely to a distribution point.
newAdvertisementStartOfferDateTime String The time when the new advertisement is first offered.
newAdvertisementStartOfferEnabled Boolean true if the advertisement is offered.

Compiling the code

The C# example requires:


  • System

  • Microsoft.ConfigurationManagement.ManagementProvider

  • Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine


  • adminui.wqlqueryengine

  • microsoft.configurationmanagement.managementprovider

  • mscorlib

Robust programming

For more information about error handling, see About Configuration Manager errors.

See also