This is part two of four in a series of articles on the new features in PowerShell 2.0. Last time we discussed background jobs, now it's time for transactions!
TransactionsWhen you run scripts, generally, three things can happen:
- The script runs, my favorite
- The script fails, this is not cool, but you can probably fix it
- The script runs only partially and dies unexpectedly in the middle of executing stuff. This is very bad and this is probably not what you want.
PowerShell 2.0 has the solution: transactions. They can help you to solve these issues and make sure the script just succeeds, or fails, but nothing inbetween.
This small script creates a transactionscope and creates a string object. Then we append some text to it twice. Once out of the transactionscope, the second time inside of the transactionscope. When we do a ToString(), we see that the text that is appended inside of the transaction is not visible at this point. This is kind of normal, because the transaction is not yet completed. Then we complete the transaction and do a ToString() again, and we can see the second text too.
Again, use the power of the shell for more info: Get-Help about_Transaction
RecourcesA list of resources on the discussed topics:
- All available cmdlets on Technet - http://technet.microsoft.com/en-us/library/dd347701.aspx
- Transactions quickstart on the official PowerShell Blog - http://blogs.msdn.com/powershell/archive/2008/05/09/powershell-transactions-quickstart.aspx