Scripting. Powershell, VMware, Windows, Active Directory & Exchange. All that kind of stuff…..
RSS icon Email icon Home icon
  • PowerShell 2.0: One Cmdlet at a Time #78 Start-Transaction

    Posted on March 17th, 2010 Jonathan Medd No comments

    Continuing the series looking at new cmdlets available in PowerShell 2.0. This time we look at the Start-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. Both cmdlets and providers can support transactions, cmdlets will have a UseTransaction parameter. To identify which cmdlets support transactions run the following:

    Get-Command | Where-Object {$_.Definition -match 'UseTransaction'}

    and for providers:

    Get-PSProvider | Where-Object {$_.Capabilities -like '*transactions*'}

    Start-Transaction begins a 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.

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

    Start-Transaction1

    You will notice that since we have not yet completed the transaction no changes have yet been made in the registry.

    Start-Transaction2

    How could I have done this in PowerShell 1.0?

    Transactional functionality was not available in PowerShell 1.0.

    1000 things 1% better!

    Leave a reply