I'm trying to use Test-Path in the registry, sample code:
$RegistryLocation = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
This works fine:
Test-Path -Path $RegistryLocation
True. Now without the final asterisk character:
$NewRegistryLocation = $RegistryLocation.Split("*")
Test-Path -Path $NewRegistryLocation
Cannot bind argument to parameter 'Path' because it is an empty string.
But this works (value of $NewRegistryLocation variable):
Test-Path -Path "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
What is happening here?
split("*")create an array with the second value being null (part after * in the original string)? Null would result in error.$NewRegistryLocationis not a string but a string array. You can view it's type by$NewRegistryLocation.GetType(). Use$NewRegistryLocation[0]