如何删除作系统部署任务序列作

通过从任务序列步骤中删除作,在 Configuration Manager 中删除作系统部署任务序列作。

删除任务序列作

  1. 设置与 SMS 提供程序的连接。 有关详细信息,请参阅 SMS 提供程序基础知识

  2. SMS_TaskSequence) 对象获取任务序列 ( 。 有关详细信息,请参阅 如何创建作系统部署任务序列

  3. SMS_TaskSequence.Steps 数组属性中删除作。

示例

以下示例方法从任务序列中删除作。 通过检查 Windows Management Instrumentation (WMI) 属性__SUPERCLASS,确保它派生自 SMS_TaskSequenceAction,作被标识为作。

有关调用示例代码的信息,请参阅调用Configuration Manager代码片段

Sub RemoveAction (connection, taskSequence, actionName)

    Dim i
    Dim newArray
    Dim actionStep

    If taskSequence.SystemProperties_("__CLASS")<>"SMS_TaskSequence" Then
        wscript.echo "Not a task sequence"
        Exit Sub
    End If

    if IsNull(taskSequence.Steps) Then
        Wscript.Echo "No steps"
        Exit Sub
    End If

    ' Create an array to hold copied steps.
    newArray = Array(taskSequence.Steps)
    ReDim newArray(UBound(taskSequence.Steps))

    ' Copy the steps into the array and remove the matching action.
    i=0
    for each  actionStep in taskSequence.Steps
        If actionStep.Name = actionName and _
          actionStep.SystemProperties_("__SUPERCLASS") = "SMS_TaskSequence_Action" Then
             ReDim preserve newArray(UBound(newArray)-1) ' shrink the Array
        else
           Set newArray(i)=actionStep ' copy it
           i=i+1
        End If
     Next

     ' Assign new array back to the task sequence.
     taskSequence.Steps=newArray

End Sub
public void RemoveAction(
    IResultObject taskSequence,
    string actionName)
{
    try
    {
        // Get a list of steps.
        List<IResultObject> actionSteps = taskSequence.GetArrayItems("Steps");

        // Find the action to be deleted.
        foreach (IResultObject actionStep in actionSteps)
        {
            if (actionStep["Name"].StringValue == actionName && actionStep["__SUPERCLASS"].StringValue == "SMS_TaskSequence_Action")
            {
                // Delete the action.
                actionSteps.Remove(actionStep);
                break;
            }
        }

        // Update the task sequence.
        taskSequence.SetArrayItems("Steps", actionSteps);
    }
    catch (Exception e)
    {
        Console.WriteLine("Failed to remove action: " + e.Message);
        throw;
    }
}

示例方法具有以下参数:

参数 类型 说明
Connection -管理:WqlConnectionManager
- VBScript: SWbemServices
与 SMS 提供程序的有效连接。
taskSequence -管理: IResultObject
- VBScript: SWbemObject
包含要删除的作的任务序列。
actionName -管理: String
- VBScript: String
要删除的作的名称。 这可以从 属性获取 SMS_TaskSequenceAction.Name

编译代码

此 C# 示例需要:

命名空间

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

可靠编程

有关错误处理的详细信息,请参阅关于Configuration Manager错误

.NET Framework 安全性

有关保护Configuration Manager应用程序的详细信息,请参阅Configuration Manager基于角色的管理

另请参阅

对象概述如何添加作系统部署任务序列作如何使用托管代码连接到 Configuration Manager 中的SMS 提供程序如何使用 WMI 任务序列在 Configuration Manager连接到 SMS 提供程序概述