PowerShell 2.0: One Cmdlet at a Time 80 Get-Transaction
Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Get-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.
Get-Transaction returns an object of a current transaction which has been kicked off with Start-Transaction.
Examples:
Start a transaction then use Get-Transaction to examine its details.
Start-Transaction Get-Transaction
Another 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. Use Get-Transaction to retrieve the details, notice that the status is Committed.
cd HKLM:\Software Start-Transaction New-Item Test -UseTransaction New-ItemProperty Test -Name TestKey -Value 1000 -UseTransaction Complete-Transaction Get-Transaction
How could I have done this in PowerShell 1.0?
Transactional functionality was not available in PowerShell 1.0.