Games: Beginner 5
This one involves setting some registry settings to increase the number of concurrent downloads. I’m running Windows 7 and IE 8 which have already increased the limits from 2 to 6. Tobias has done a really good job on his expert commentary - http://blogs.technet.com/heyscriptingguy/archive/2009/06/18/hey-scripting-guy-event-5-solutions-from-expert-commentators-beginner-and-advanced-the-400-meter-race.aspx - so rather than repeat that I’m going to use this as an example of using transactions in PowerShell v2.
| 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026
| #Requires -version 2.0 #IE 8 increases limit to 6 from 2 #need to create keys cls cd "HKCU:\Software\Microsoft\Windows\CurrentVersion" "Before" Get-ItemProperty "Internet Settings" Start-Transaction New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ` -Name MaxConnectionsPerServer -PropertyType DWORD -Value 10 -UseTransaction | Out-Null New-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ` -Name MaxConnectionsPer1_0Server -PropertyType DWORD -Value 10 -UseTransaction | Out-Null "During" Get-ItemProperty "Internet Settings" -UseTransaction Read-Host "Continue" Undo-Transaction "After" Get-ItemProperty "Internet Settings" cd \ cd c: |
Use Requires to restrict to PowerShell v2
use the registry provider to navigate to the location of the settings and use get-itemproperty to display the values
We can then start our transaction. Make the changes and display the properties again. Notice that we have to use the
-UseTransaction parameter to involve these cmdlets in the transaction. A Read-Host is used to pause the script. Check the values and we can seen that the properties have been added. Continue the script by pressing any key (if you can find it) and then the transaction will undo. Display the properties again to show that the change has been undone.
Transactions are only available on the Registry provider at the moment. Hopefully, they will be extended onto the other providers in the next version of PowerShell.