Windows Dev Center

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

How to Support Transactions

This example shows the basic code elements that add support for transactions to a cmdlet.

ImportantImportant
For more information about how Windows PowerShell handles transactions, see Windows PowerShell Transactions.

To support transactions

  1. When you declare the Cmdlet attribute, specify that the cmdlet supports transactions. When the cmdlet supports transactions, Windows PowerShell adds the UseTransaction parameter to the cmdlet when it is run.

      [Cmdlet(VerbsCommunications.Send, "GreetingTx", 
              SupportsTransactions=true )]
    
  2. Within one of the input processing methods, add an if block to determine if a transaction is available. If the if statement resolves to true, the actions within this statement can be performed within the context of the current transaction.

          if (TransactionAvailable())
          {
            using (CurrentPSTransaction)
            {
              WriteObject("Hello " + name + "  from within a transaction.");
            }
          }
    

See Also

Community Additions

Show:
© 2015 Microsoft