Michael Niehaus pointed out that there's a method called SetSequence() on
the SMS_TaskSequencePackage class. Let me try to modify the PowerShell code
to use this, and see if it works.

 

Cheers,

Trevor Sullivan

 

From: [email protected] [mailto:[email protected]]
On Behalf Of Ryan
Sent: Wednesday, March 19, 2014 10:15 AM
To: [email protected]
Subject: Re: [mssms] Modify Task Sequences with a Script

 

Yes, the C# code is.  This is how they set a new task sequence variable:

 

public void AddTaskSequenceVariable(
    WqlConnectionManager connection, 
    IResultObject taskSequence, 
    string variableName, 
    string variableValue)
{
    try
    {
        // Create the task sequence variable object.
        IResultObject variable =
connection.CreateEmbeddedObjectInstance("SMS_TaskSequence_SetVariableAction"
);
 
        // Populate the properties.
        variable["Name"].StringValue = "MyTaskSequenceVariable";
        variable["ContinueOnError"].BooleanValue = false;
        variable["Description"].StringValue = "A task sequence variable set
with SMS_TaskSequence_SetVariableAction";
        variable["Enabled"].BooleanValue = true;
        variable["VariableName"].StringValue = variableName;
        variable["VariableValue"].StringValue = variableValue;
 
        // Add the step to the task sequence.
        List<IResultObject> array = taskSequence.GetArrayItems("Steps");
 
        array.Add(variable);
        taskSequence.SetArrayItems("Steps", array);
    }
    catch (SmsException e)
    {
        Console.WriteLine("Failed to set task sequence variable: " +
e.Message);
        throw;
    }
}
 
It seems to be the same kind of code that Trevor had so I'm not sure why his
didn't work.

 

On Tue, Mar 18, 2014 at 4:45 PM, Daniel Ratliff <[email protected]
<mailto:[email protected]> > wrote:

Hmm is it still leveraging wmi?

-Daniel Ratliff



-----Original Message-----
From: Ryan [[email protected] <mailto:[email protected]> ]
Sent: Tuesday, March 18, 2014 05:30 PM Eastern Standard Time
To: [email protected] <mailto:[email protected]> 
Subject: Re: [mssms] Modify Task Sequences with a Script

Cool, I voted it up also.  Thanks! 

 

There is some C# code in the SDK I've found to add steps to a task sequence.
I may look at taking that information and creating some functions or cmdlets
to do this.

 

On Tue, Mar 18, 2014 at 4:03 PM, Trevor Sullivan <[email protected]
<mailto:[email protected]> > wrote:

Voted.

 

Cheers,

Trevor Sullivan

 

From: [email protected] <mailto:[email protected]>
[mailto:[email protected]
<mailto:[email protected]> ] On Behalf Of Daniel Ratliff
Sent: Tuesday, March 18, 2014 4:01 PM


To: [email protected] <mailto:[email protected]> 
Subject: RE: [mssms] Modify Task Sequences with a Script

 

Here you go. Vote away! Also threw a post out on myItForum. Feel free to put
any suggestions out there. 

 

https://connect.microsoft.com/ConfigurationManagervnext/feedback/details/836
341/dcr-ability-to-modify-existing-task-sequence-via-powershell-wmi

 

From: [email protected] <mailto:[email protected]>
[mailto:[email protected]
<mailto:[email protected]> ] On Behalf Of Daniel Ratliff
Sent: Tuesday, March 18, 2014 3:18 PM
To: [email protected] <mailto:[email protected]> 
Subject: RE: [mssms] Modify Task Sequences with a Script

 

Hmm, great idea for a DCR. Ill open it on Connect later today, unless
someone beats me to it.

 

From: [email protected] <mailto:[email protected]>
[mailto:[email protected]]
<mailto:[mailto:[email protected]]>  On Behalf Of Trevor
Sullivan
Sent: Tuesday, March 18, 2014 3:14 PM
To: [email protected] <mailto:[email protected]> 
Subject: RE: [mssms] Modify Task Sequences with a Script

 

+1

 

I just tried writing up the script below, but it didn't end up persisting
the changes.

 

Cheers,

Trevor Sullivan

 

# Specify the task sequence package ID

$PackageID = 'LAB00012';

 

# 1. Get the task sequence package using fully qualified WMI path

$TaskSequence =
[wmi]"root\sms\site_lab:SMS_TaskSequencePackage.PackageID='LAB00012'";

# 2. Get reference to the SMS_TaskSequence class

$TsClass = [wmiclass]"root\sms\site_lab:SMS_TaskSequence"

# 3. Load the XML from the task sequence's "Sequence" property into a
SMS_TaskSequence instance

$TS = $TsClass.LoadFromXml($TaskSequence.Sequence).ReturnValue;

 

# 4. Get a reference to one of the task sequence step types

$SetVarClass =
[wmiclass]"root\sms\site_lab:SMS_TaskSequence_SetVariableAction"

# 5. Instantiate the task sequence action class

$NewSetVarAction = $SetVarClass.CreateInstance();

# 6. Set appropriate properties on the Action

$NewSetVarAction.Name = '[PowerShell] Set Variable';

$NewSetVarAction.VariableName = 'OSDPreserveDriveLetter';

$NewSetVarAction.VariableValue = 'False';

 

# 7. Add the Action to the task sequence steps

$TS.Steps += $NewSetVarAction;

# 8. Commit the modified WMI object back into XML

$NewTS = $TsClass.SaveToXml($TS);

# 9. Set the XML on the Sequence property of the SMS_TaskSequence

$TaskSequence.Sequence = $NewTS.ReturnValue;

# 10. Commit the task sequence changes to WMI

$TaskSequence.Put();

 

 

From: [email protected] <mailto:[email protected]>
[mailto:[email protected]]
<mailto:[mailto:[email protected]]>  On Behalf Of Daniel
Ratliff
Sent: Tuesday, March 18, 2014 2:02 PM
To: [email protected] <mailto:[email protected]> 
Subject: RE: [mssms] Modify Task Sequences with a Script

 

I have tried this for a good year now. I can export them and document them,
but don't have a way to edit them on the fly without creating new ones with
the changes. 

 

From: [email protected] <mailto:[email protected]>
[mailto:[email protected]]
<mailto:[mailto:[email protected]]>  On Behalf Of Ryan
Sent: Tuesday, March 18, 2014 2:52 PM
To: [email protected] <mailto:[email protected]> 
Subject: [mssms] Modify Task Sequences with a Script

 

Does anyone here know how to modify a task sequence with a script?

 

I'm taking adding task sequence variables, application install steps, driver
steps, etc etc...

 

I'd very much like to make tools to make some task sequence creation steps
easier and I don't want to have to learn C# to do it.

 


The information transmitted is intended only for the person or entity to
which it is addressed
and may contain CONFIDENTIAL material. If you receive this
material/information in error,
please contact the sender and delete or destroy the material/information.

 

 


The information transmitted is intended only for the person or entity to
which it is addressed
and may contain CONFIDENTIAL material. If you receive this
material/information in error,
please contact the sender and delete or destroy the material/information.

 


The information transmitted is intended only for the person or entity to
which it is addressed
and may contain CONFIDENTIAL material. If you receive this
material/information in error,
please contact the sender and delete or destroy the material/information.

 

 

 



The information transmitted is intended only for the person or entity to
which it is addressed
and may contain CONFIDENTIAL material. If you receive this
material/information in error,
please contact the sender and delete or destroy the material/information.

 

 

 



Reply via email to