Transactions

A transaction allows a set of changes to be grouped together and committed at the same time. Transactions are only supported under Windows PowerShell.

The registry provider supports transactions, as shown in the following code:

PS> Get-PSProvider

Name Capabilities Drives
---- ------------ ------
Registry ShouldProcess, Transactions {HKLM, HKCU}
Alias ShouldProcess {Alias}
Environment ShouldProcess {Env}
FileSystem Filter, ShouldProcess, Credentials {B, C, D}
Function ShouldProcess {Function}
Variable ShouldProcess {Variable}

A transaction may be created as follows:

Start-Transaction 
$path = 'HKCU:TestTransaction' 
New-Item $path -ItemType Key -UseTransaction 
Set-ItemProperty $path -Name 'Name' -Value 'Transaction' -UseTransaction 
Set-ItemProperty $path -Name 'Length' -Value 20 -UseTransaction 

At this point, the transaction may be undone:

Undo-Transaction 

Alternatively, the transaction may be committed:

Complete-Transaction 

A list of the commands that support transactions may be viewed, although not all of these may be used with the registry provider:

Get-Command -ParameterName UseTransaction 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.86.56