Search code examples
windowspowershellregistrypowershell-2.0powershell-4.0

Test-Path Returning false eventhough it exists


Powershell command showing false , even though that path exist in registry, what wrong i am doing?

PS D:\Folder> Test-Path -Path 'HKU:\S-9-9-21-57989841-616249376-1801674531-2451702'
False

enter image description here


Solution

  • Drive HKU: is not defined by default.

    Either use:

    Test-Path -Path 'Registry::HKEY_USERS\S-9-9-21-57989841-616249376-1801674531-2451702'
    

    or define the drive first:

    $null = New-PSDrive -Name HKU -PSProvider Registry -Root HKEY_USERS
    Test-Path -Path 'HKU:\S-9-9-21-57989841-616249376-1801674531-2451702'
    

    and when finished remove that drive with Remove-PSDrive -Name HKU