Created
June 10, 2015 17:12
-
-
Save MattHodge/0f7e16f92448c619dcbc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#---------------------------------------------------------[Initialisations]-------------------------------------------------------- | |
# Makes PowerShell pull you up about everything.. | |
Set-StrictMode -Version Latest | |
# YOu don't need to put this in usually, but just to make sure in your ise. | |
$ErrorActionPreference = "Continue" | |
#Dot Source required Function Libraries | |
#. "Logging_Functions.ps1" | |
#----------------------------------------------------------[Declarations]---------------------------------------------------------- | |
#Script Version | |
$sScriptVersion = "1.0" | |
#Log File Info | |
$sLogPath = "C:\Windows\Temp" | |
$sLogName = "skysail_reg_replace.log" | |
$sLogFile = Join-Path -Path $sLogPath -ChildPath $sLogName | |
#-----------------------------------------------------------[Functions]------------------------------------------------------------ | |
New-Item -Path $LogPath -Name $LogName ItemType File | |
# Global Variables | |
# Don't have this going to null.. hides the output from you | |
$null = New-PSDrive -Name HKEY -PSProvider Registry -Root Registry: HKEY_CURRENT_USER -Root Registry: HKEY_LOCAL_MACHINE | |
#Enter the string value to search for in the variable below. | |
$SearchString = "skysail" | |
#================================================================================== | |
# Main Code for HKCU: | |
# Write a message to the user to let them know the script | |
# has started. | |
Write-Host "Searching: HKCU" | |
# Search the registry for the string value. Store | |
# Registry Keys in $HKCUValues variable | |
# Take your error actions off - let it do the default which is to show you the error, but continue.. | |
$HKCUValues = Get-ChildItem HKCU:\ -Recurse -ErrorAction SilentlyContinue | | |
ForEach-Object | |
{ | |
if((get-itemproperty -Path $_.PsPath) -match $searchString) | |
{ | |
$_.PsPath | |
} | |
} | |
# Registry Keys in $HKLMValues variable | |
$HKLMValues = Get-ChildItem HKLM:\ -Recurse -ErrorAction SilentlyContinue | | |
ForEach-Object | |
{ | |
if((get-itemproperty -Path $_.PsPath) -match $searchString) | |
{ | |
$_.PsPath | |
} | |
} | |
# Write a message to let the user know the script completed. | |
Write-Host "Part1 has completed." | |
# == End of Main Code ======================================= | |
# Replace to make it look pretty | |
ForEach ($line in $HKCUValues) | |
{ | |
$line -replace "Hkey_Current_User", "HKCU" | |
} | |
# Run Through the $HKCUValues variable and set the values below in the registry. | |
ForEach ($data in $HKCUValues) | |
{ | |
Set-ItemProperty -Path $data -Value "0" -type Dword | |
} | |
Write-Host "Changes in Registry for HKCU Completed" | |
ForEach ($line in $HKLMValues) | |
{ | |
$line -replace "HKEY_LOCAL_MACHINE", "HKLM" | |
} | |
# Run Through the $HKLMValues variable and set the values below in the registry. | |
ForEach ($data in $HKLMValues) | |
{ | |
Set-ItemProperty -Path $data -Value "0" -type Dword | |
} | |
Write-Host "Changes in Registry for HKLM Completed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment