Add a script block to the active transaction.

      Use-Transaction [-TransactedScript] scriptblock 
         [-UseTransaction] [CommonParameters]

   -TransactedScript scriptblock
      The script block that is run in the transaction.
      Enter any valid script block enclosed in braces {  }
      This parameter is required.

       Include the command in the active transaction.


Show the effect of rolling back a transaction that includes Use-Transaction commands. When the transaction is rolled back, the transacted changes are discarded and the data is unchanged:

PS C:\> Start-transaction
PS C:\> $myTxString = New-Object Microsoft.PowerShell.Commands.Management.TransactedString
PS C:\> $myTxString.Append("Hello")
PS C:\> use-transaction -TransactedScript { $myTxString.Append(", World") } -UseTransaction
PS C:\> Undo-transaction
PS C:\> $myTxString.ToString()

“Two roads diverged in a wood, and I, I took the one less traveled by, And that has made all the difference” ~ Robert Frost (The Road Not Taken)

Related PowerShell Cmdlets

Start-Transaction - Start a new transaction.
- Commit the transaction.
Get-Transaction - Get information about the active transaction.
Undo-Transaction - Roll back a transaction.

Copyright © 1999-2024
Some rights reserved