Reader small image

You're reading from  Mastering PowerShell Scripting - Fourth Edition

Product typeBook
Published inJun 2021
PublisherPackt
ISBN-139781800206540
Edition4th Edition
Right arrow
Author (1)
Chris Dent
Chris Dent
author image
Chris Dent

Chris Dent is an automation specialist with deep expertise in the PowerShell language. Chris is often found answering questions about PowerShell in both the UK and virtual PowerShell user groups. Chris has been developing in PowerShell since 2007 and has released several modules over the years.
Read more about Chris Dent

Right arrow

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 in Windows, 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} 

You can create a transaction as follows:

Start-Transaction 
$path = 'HKCU:\TestTransaction' 
New-Item $path -ItemType Key -UseTransaction 
Set-ItemProperty $path -Name 'Name' -Value...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Mastering PowerShell Scripting - Fourth Edition
Published in: Jun 2021Publisher: PacktISBN-13: 9781800206540

Author (1)

author image
Chris Dent

Chris Dent is an automation specialist with deep expertise in the PowerShell language. Chris is often found answering questions about PowerShell in both the UK and virtual PowerShell user groups. Chris has been developing in PowerShell since 2007 and has released several modules over the years.
Read more about Chris Dent