您可以將步驟新增至陣列屬性, (Configuration Manager 將動作或群組) 加入作系統部署工作順序群組SMS_TaskSequenceGroup.Steps。
將步驟新增至工作順序群組
設定與SMS提供者的連線。 如需詳細資訊,請 參閱SMS提供者基本概念。
取得您要新增步驟的 SMS_TaskSequenceGroup 物件。 如需詳細資訊,請參閱 如何建立作系統部署工作順序群組。
建立工作順序步驟。 如需建立動作步驟的範例,請參閱 如何新增作系統部署工作順序動作。
將步驟新增至陣
SMS_TaskSequenceGroup.Steps列屬性。視需要重新排序陣列屬性內的步驟。 如需詳細資訊,請參閱 如何重新排序作系統部署工作順序
範例
下列範例方法會將命令行動作新增至工作順序群組。
如需呼叫範例程式代碼的相關信息,請參閱呼叫 Configuration Manager 代碼段。
Sub AddStepToGroup(taskSequenceStep, group)
Dim steps
' If needed, create a new steps array.
If IsNull(group.Steps) Then
steps = Array(taskSequenceStep)
group.Steps=steps
Else
' Resize the existing steps and add step.
steps= Array(group.Steps)
ReDim steps (UBound (group.Steps)+1)
group.Steps(UBound(steps))=taskSequenceStep
End if
End Sub
public void AddStepToGroup(
WqlConnectionManager connection,
IResultObject taskSequence,
string groupName)
{
try
{
// Get the group.
List<IResultObject> steps = taskSequence.GetArrayItems("Steps"); // Array of SMS_TaskSequence_Steps.
foreach (IResultObject ro in steps)
{
if (ro["Name"].StringValue == groupName && ro["__CLASS"].StringValue == "SMS_TaskSequence_Group")
{
IResultObject action = connection.CreateEmbeddedObjectInstance("SMS_TaskSequence_RunCommandLineAction");
action["CommandLine"].StringValue = @"C:\donowtingroup.bat";
action["Name"].StringValue = "Action in group " + groupName;
action["Description"].StringValue = "Action in a group";
action["Enabled"].BooleanValue = true;
action["ContinueOnError"].BooleanValue = false;
// Add the step to the task sequence.
List<IResultObject> array = ro.GetArrayItems("Steps");
array.Add(action);
ro.SetArrayItems("Steps", array);
taskSequence.SetArrayItems("Steps", steps);
break;
}
}
}
catch (SmsException e)
{
Console.WriteLine("Failed to create Task Sequence: " + e.Message);
throw;
}
}
範例方法具有下列參數:
| 參數 | Type | 描述 |
|---|---|---|
connection |
-管理: WqlConnectionManager- VBScript: SWbemServices |
SMS 提供者的有效連線。 |
taskSequencetaskSequenceStep |
-管理: IResultObject- VBScript: SWbemObject |
- 包含群組的有效工作順序 (SMS_TaskSequence) 。 |
groupNamegroup |
-管理: String- VBScript: String |
加入命令行動作的組名。 這是從 SMS_TaskSequenceGroup.Name 屬性取得。 |
正在編譯程式碼
此 C# 範例需要:
命名空間
系統
System.Collections.Generic
System.Text
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
組件
microsoft.configurationmanagement.managementprovider
adminui.wqlqueryengine
健全的程式設計
如需錯誤處理的詳細資訊,請參閱關於 Configuration Manager 錯誤。
.NET Framework 安全性
如需保護 Configuration Manager 應用程式的詳細資訊,請參閱 Configuration Manager 角色型系統管理。
另請參閱
物件概觀 如何使用 Managed 程式代碼連線到 Configuration Manager 中的 SMS 提供者如何使用 WMI 如何將步驟移至不同的作系統部署工作順序群組如何建立作系統部署工作順序群組,以聯機到 Configuration Manager 中的 SMS 提供者如何從作系統部署群組工作順序概觀中移除步驟