Add a script block to the active transaction.
Syntax Use-Transaction [-TransactedScript] scriptblock [-UseTransaction] [CommonParameters] Key -TransactedScript scriptblock The script block that is run in the transaction. Enter any valid script block enclosed in braces { } This parameter is required. -UseTransaction 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()
Hello
“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)
Start-Transaction - Start a new transaction.
Complete-Transaction - Commit the transaction.
Get-Transaction - Get information about the active transaction.
Undo-Transaction - Roll back a transaction.