How to Use transaction with Powershell

Posted by & filed under .

 

If i am wrong please correct me , i know this feature came with Windows Powershell 2.0.

Start-Transaction

This is the command. When you write this on the command line , you will see the detailed prompt.

$transactionKelime= New-Object Microsoft.PowerShell.Commands.Management.TransactedString
$transactionKelime.Append("Trying")
Use-Transaction -TransactedScript {$transactionKelime.Append("Finished") } -UseTransaction

‘Use-transaction’

When you write this command you will see another detailed prompt.

ps2

$transactionKelime.ToString()

First we tried to use transaction before it started.

Now we will try after it started.

 Use-Transaction -TransactedScript {$transactionKelime.ToString()}  -UseTransaction

ps3

There is an another prompt , you have to use transactions with transaction-enabled objects ( you can see all the objects with the command below)

 Get-PSProvider

Finally we are completing the transaction.

 
Complete-Transaction
$transactionKelime.ToString()

If we used ‘undo-transaction’ it would have prompted “deneme”. You can try the script below.

 
$transactionKelime= New-Object Microsoft.PowerShell.Commands.Management.TransactedString
$transactionKelime.Append("Trying")
Use-Transaction -TransactedScript {$transactionKelime.Append(" Finished") } -UseTransaction
$transactionKelime.ToString()
Use-Transaction -TransactedScript {$transactionKelime.ToString()}  -UseTransaction
 Undo-Transaction
$transactionKelime.ToString()

2 Responses to “How to Use transaction with Powershell”

  1. Best beard oil

    Thanks so much for the blog.Really looking forward to read more. Want more.

    Reply
  2. kibris bahis siteleri

    Very good article.Much thanks again. Awesome.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *