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
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
PowerShell