Code/Test-PathReg.ps1

#requires -version 2.0
###############################################################################
# WintellectPowerShell Module
# Copyright (c) 2010-2014 - John Robbins/Wintellect
#
# Do whatever you want with this module, but please do give credit.
###############################################################################

# Always make sure all variables are defined and all best practices are
# followed.
Set-StrictMode -version Latest

###############################################################################
# Public Cmdlets
###############################################################################
function Test-PathReg
{
<#
.SYNOPSIS
Validates the existence of a registry key
 
.DESCRIPTION
This function searches for the registry value (Property attribute) under the
given registry key (Path attribute) and returns $true if it exists.
Author: Can Dedeoglu (Thanks Can!)
 
.PARAMETER Path
Specifies the Registry path.
 
.PARAMETER Property
Specifies the name of the registry property that will be searched for under the
given Registry path.
 
.EXAMPLE
C:\PS> Test-PathReg -Path HKLM:\SYSTEM\CurrentControlSet\services\Tcpip\Parameters -Property Hostname
 
Checks to see if the Hostname property exists in the HKLM:\SYSTEM\CurrentControlSet\services\Tcpip\Parameters registry key
 
.LINK
http://blogs.msdn.com/candede
 
#>

    param (
        [Parameter(mandatory=$true,position=0)]
        [string]$Path,
        [Parameter(mandatory=$true,position=1)]
        [string]$Property )


    $compare = (Get-ItemProperty -LiteralPath $Path).psbase.members | `
                    ForEach-Object {$_.name} | `
                    Compare-Object $Property -IncludeEqual -ExcludeDifferent
    if($null -eq $compare)
    {
        return $false
    }
    if($compare.SideIndicator -like "==") 
    {
        return $true
    }
    else
    {
        return $false
    }
}

# SIG # Begin signature block
# MIIYTQYJKoZIhvcNAQcCoIIYPjCCGDoCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUN9ZJ20I0UmqaYsosYRdcicpZ
# QwagghM9MIIEhDCCA2ygAwIBAgIQQhrylAmEGR9SCkvGJCanSzANBgkqhkiG9w0B
# AQUFADBvMQswCQYDVQQGEwJTRTEUMBIGA1UEChMLQWRkVHJ1c3QgQUIx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