How to Create a Deployment Template
Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager
You create a software updates deployment template, in System Center 2012 R2 Configuration Manager, by creating an instance of the SMS_Template class and populating the properties.
To create a deployment template
Set up a connection to the SMS Provider.
Create the new template object by using the SMS_Template class.
Populate the new template properties.
Save the new template and properties.
Example
The following example method shows how to create a software updates deployment template by using the SMS_Template class and class properties.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Note: In the following code examples, the template settings are passed into the method by using a string variable called deploymentTemplateSettings. The template settings are stored in an XML structure.
VB Template Setting Example (one long string):
deploymentTemplateSettings = "<TemplateDescription xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""> <CollectionId>SMS00001</CollectionId> <IncludeSub>true</IncludeSub> <AttendedInstall>true</AttendedInstall> <UTC>true</UTC> <Duration>2</Duration> <DurationUnits>Weeks</DurationUnits> <SuppressServers>Unchecked</SuppressServers> <SuppressWorkstations>Unchecked</SuppressWorkstations> <AllowRestart>false</AllowRestart> <Deploy2003>true</Deploy2003> <CollectImmediately>false</CollectImmediately> <LocalDPOption>DownloadAndInstall</LocalDPOption> <RemoteDPOption>DownloadAndInstall</RemoteDPOption> <DisableMomAlert>false</DisableMomAlert> <GenerateMomAlert>false</GenerateMomAlert> <UseRemoteDP>false</UseRemoteDP> <UseUnprotectedDP>false</UseUnprotectedDP> </TemplateDescription>"
C# Template Setting Example (the same template settings and still passed as a string, but the XML structure is more obvious).
string deploymentTemplateSettings =
@"<TemplateDescription xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<CollectionId>SMS00001</CollectionId>
<IncludeSub>true</IncludeSub>
<AttendedInstall>true</AttendedInstall>
<UTC>true</UTC>
<Duration>2</Duration>
<DurationUnits>Weeks</DurationUnits>
<SuppressServers>Unchecked</SuppressServers>
<SuppressWorkstations>Unchecked</SuppressWorkstations>
<AllowRestart>false</AllowRestart>
<Deploy2003>true</Deploy2003>
<CollectImmediately>false</CollectImmediately>
<LocalDPOption>DownloadAndInstall</LocalDPOption>
<RemoteDPOption>DownloadAndInstall</RemoteDPOption>
<DisableMomAlert>false</DisableMomAlert>
<GenerateMomAlert>false</GenerateMomAlert>
<UseRemoteDP>false</UseRemoteDP>
<UseUnprotectedDP>false</UseUnprotectedDP>
</TemplateDescription>";
Sub CreateSUMDeploymentTemplate(connection, _
newTemplateName, _
newTemplateDescription, _
newTemplateSettings, _
newTemplateType)
' Create the new Template object.
Set newSUMTemplate = connection.Get("SMS_Template").SpawnInstance_
' Populate the SMS_Template properties.
' Note: The template name (newTemplateName) must be unique.
newSUMTemplate.Name = newTemplateName
newSUMTemplate.Description = newTemplateDescription
newSUMTemplate.Data = newTemplateSettings
newSUMTemplate.Type = newTemplateType
' Save the new template and properties.
newSUMTemplate.Put_
' Output the new template name.
Wscript.Echo "Created new template: " & newTemplateName
End Sub
public void CreateSUMDeploymentTemplate(WqlConnectionManager connection,
string newTemplateName,
string newTemplateDescription,
string newTemplateSettings,
int newTemplateType)
{
try
{
// Create the template object.
IResultObject newSUMTemplate = connection.CreateInstance("SMS_Template");
// Populate the new template properties.
// Note: The template name (newTemplateName) must be unique.
newSUMTemplate["Name"].StringValue = newTemplateName;
newSUMTemplate["Description"].StringValue = newTemplateDescription;
newSUMTemplate["Data"].StringValue = newTemplateSettings;
newSUMTemplate["Type"].IntegerValue = newTemplateType;
// Save the new template and the new template properties.
newSUMTemplate.Put();
// Output the new template name.
Console.WriteLine("Created template: " + newTemplateName);
}
catch (SmsException ex)
{
Console.WriteLine("Failed to create template. Error: " + ex.Message);
throw;
}
}
This example method has the following parameters:
Parameter |
Type |
Description |
||||||||||||||||||||||||||||||||||
connection |
|
A valid connection to the SMS Provider. |
||||||||||||||||||||||||||||||||||
newTemplateName |
|
|
||||||||||||||||||||||||||||||||||
newTemplateDescription |
|
The description for the new template. |
||||||||||||||||||||||||||||||||||
newTemplateSettings |
|
The new template settings. The settings are in an XML structure, stored as a string.
|
||||||||||||||||||||||||||||||||||
newTemplateType |
|
The new template type. Currently the only possible value is:
|
Compiling the Code
This C# example requires:
Namespaces
System
System.Collections.Generic
System.Text
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
.NET Framework Security
For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.
See Also
System Center 2012 R2 Configuration Manager SDK
Configuration Manager Software Updates
Software Updates Deployments
How to Assign a Package to a Distribution Point
SMS_Template Server WMI Class