Code/Test-PathReg.ps1
#requires -version 5.0 ############################################################################### # WintellectPowerShell Module # Copyright (c) 2010-2017 - 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 ) $gipReturn = Get-ItemProperty -LiteralPath $Path -ErrorAction SilentlyContinue if ($null -eq $gipReturn) { return $false } $compare = $gipReturn.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 # MIIaQwYJKoZIhvcNAQcCoIIaNDCCGjACAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR # AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUNk9kJNGEGSchJ4MYiFS5ehQ4 # onCgghUyMIIEmTCCA4GgAwIBAgIPFojwOSVeY45pFDkH5jMLMA0GCSqGSIb3DQEB # BQUAMIGVMQswCQYDVQQGEwJVUzELMAkGA1UECBMCVVQxFzAVBgNVBAcTDlNhbHQg # TGFrZSBDaXR5MR4wHAYDVQQKExVUaGUg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