Create a fully function Task Sequence in seconds with PowerShell

If you are like me and prefer a command window to a wizard, then this post might be for you. The script (download link at the bottom) will generate a fully functional Task Sequence in seconds with just a few parameters. This script leverage PowerShell steps in the Task Sequence to simulate the traditional MDT Integrated Task Sequence “Gather” step. No MDT integration is required to create or deploy this Task Sequence.

Parameters

You will need proper permissions within Configuration Manager. If you can create a Task Sequence in the console, you can create it from PowerShell! In addition, you will need the following bits of information to use as parameter values before you start:

  • Org = Your Organization Name.
  • OSPackageID = The PackageID of the OS Image that will be deployed with this Task Seqeunce.
  • HydrationRevision (optional) = You can add a unique identifier that will be appended to the Task Sequence name.
  • BootImageID = The PackageID of the Windows PE Boot Image you want to attach to this Task Sequence.
  • Windows = The version of Windows you are deploying. (i.e. Windows 10, or Windows 11)
  • WindowsReleaseID = The release version of Windows (i.e. 22H2, 23H2, etc.)
  • OSEdition = Enterprise or Professional
  • DomainName = The dns name of the domain you are joining the device to.
  • MachineObjectOU = The LDAP representation of the OU you where you want to device to reside. (ensure domain join account has delegated rights!)
    • Example: LDAP://OU=MyDevices,DC=MyCompany,DC=com
  • Comment = A comment that will be prepended to the description property of the Task Sequence.

Executing the script

  1. From your Configuration Manager server, open an Administrative PowerShell window.
  2. Navigate to the directory where you saved the script.
  3. Run the script providing the parameters discussed above. Example:
 .\New-WindowsTaskSequence.ps1 -Org "Myorg" -OSPackageID "LAB00007" -HydrationRevision "R03" -BootImageID "LAB00002" -Windows "Windows 11" -WindowsReleaseID "23H3" -OSEdition "Enterprise" -DomainName "contoso.org" -MachineObjectOU "LDAP://OU=Devices,DC=contoso,DC=org" -Comment "Testing TS Automation"

Once the script has completed there are notes to remind you to modify the task sequence before testing as it uses dummy account information so that credentials are NOT stored in the script.

The New Sequence will appear in the Admin Console. Edit the Task Sequence and make any changes as you see fit. (although for the TS to run you only need to change the admin password and domain join credentials as shown)

Conclusion

Now this is just one example of how to generate a Task Sequence from PowerShell. It’s not a trivial process to create a new Task Sequence however with PowerShell by your side you can certainly turn hours or days into seconds. I hope this sparks your imagination to create new and improved versions! Happy scripting. 🙂

Download the script below.

Leave a comment