Posted On September 3, 2020

PowerShell: Check Registry Path, Key, and Dword Value

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Check Registry Path, Key, and Dword Value
$path='HKLM:\Software\Intel'
$keyName='GMM'
$dwordName='DedicatedSegmentSize'
$dwordValue=512

Function CheckRegistryKey {
    param(
        [Parameter(Position = 0, Mandatory = $true)][String]$path,
        [Parameter(Position = 1, Mandatory = $true)][String]$keyName,
        [Parameter(Position = 2, Mandatory = $false)]$dwordName,
        [Parameter(Position = 3, Mandatory = $false)]$dwordValue
    ) 
    try{
        $keyPath="$path\$keyName"
        $keyExists=gi -Path $keyPath -ea Stop
        $message=''
        if($keyExists){
            $message+="$keyPath is valid`r`n"
            if($dwordValue -and $dwordName){
                $dwordValueExists=$keyExists.getvalue($dwordName)
                if($dwordValueExists -ne $dwordValue){
                    $message+="$dwordValueExists does not match $dwordValue."
                    $result=$false
                }else{
                    $message+="Existing dword value $dwordValueExists matches the desired value of $dwordValue."
                    $result=$true
                    }
            }else{
                $result=$true
                }
        }else{
            $message+="$keyPath is invalid"
            }
        write-host $message
        return $result
    }catch{
        Write-Error $_
        return $false
        }
}

CheckRegistryKey $path $keyName $dwordName $dwordValue

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Basic HTML and HTML5: Use HTML5 to Require a Field

<h2>CatPhotoApp</h2><main><p>Click here to view more <a href="#">cat photos</a>.</p><a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying…

PowerShell: Update CSV File Using Active Directory

# adAccountsCsvUpdate.ps1 $originalCsv='C:\Users\rambo\Desktop\kimconnectUsers.csv' $newCsv='C:\Users\rambo\Desktop\kimconnectUsers-processed.csv' $newEmailSuffix='@kimconnect.com' $newOu='OU=Test,DC=kimconnect,DC=com' function adAccountsCsvUpdate{ param( $originalCsv, $newCsv, $newEmailSuffix, $newOu ) function…

HAProxy on CentOS 7

# Install HAProxy 1.8 using SCL repo yum install centos-release-scl yum install rh-haproxy18-haproxy rh-haproxy18-haproxy-syspaths  …