function Test-RegistryPath {
param(
[Alias("PSPath")]
[Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[String]$Path
,
[Parameter(Position = 2, Mandatory = $false)]
[ValidateSet('Any','Container','Leaf')]
[String]$PathType = 'Any'
)
process {
$Properties = @{
Container = $false
Leaf = $false
}
try {
$Properties.Container = Test-Path -Path $Path -PathType Container
$Properties.Leaf = (Get-Item -Path (Split-Path -Path $Path) -ErrorAction SilentlyContinue).GetValue((Split-Path -Path $Path -Leaf), $null) -ne $null
} catch {}
switch ($PathType) {
'Any' {
($Properties.Container -eq $true -or $Properties.Leaf -eq $true)
}
'Container' {
($Properties.Container -eq $true)
}
'Leaf' {
($Properties.Leaf -eq $true)
}
}
}
}