How to Support Transactions
This example shows the basic code elements that add support for transactions to a cmdlet.
Important
For more information about how Windows PowerShell handles transactions, see About Transactions.
To support transactions
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 )]
Within one of the input processing methods, add an
if
block to determine if a transaction is available. If theif
statement resolves totrue
, 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
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應