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

PowerShell: Check if a HostName is Resolvable on All Internal DNS Servers

# Check if servername is resolvable at all DCs$serverName="MIGRATED-SHERVER" function checkDns{ param( $serverName, $dnsServers=(Get-ADDomainController -Filter…

CSS

position: absolute | relative This is referencing the first parent element. Absolute means it's removed…

Notable Features of C#

This language is part of the .NET framework that can be used to build applications…