PowerShell 2.0: One Cmdlet at a Time 79 Complete-Transaction

Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Complete-Transaction cmdlet.

What can I do with it?

PowerShell 2.0 introduces new functionality in the form of transactions. By grouping together a set of commands to form a transaction they can either all be committed or all rolled back depending on success.

Complete-Transaction commits a transaction which has been kicked off with Start-Transaction.

Example:

A good example of a possible use for transactions is within the registry. Change directory into the registry provider. Begin a new transaction and use the New-Item and New-ItemProperty cmdlets to potentially create entries within the registry. Use Complete-Transaction to commit these changes.

cd HKLM:\Software Start-Transaction New-Item Test -UseTransaction New-ItemProperty Test -Name TestKey -Value 1000 -UseTransaction Complete-Transaction

You will notice that after completing the transaction the changes have been made in the registry.

How could I have done this in PowerShell 1.0?

Transactional functionality was not available in PowerShell 1.0.

1000 things 1% better!