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
PowerShell
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기