How to Fix “A drive with the name ‘HKU’ does not exist” on PowerShell

How to fix “A drive with the name ‘HKU’ does not exist” on Powershell

The error:

 

Cannot find drive. A drive with the name ‘HKU’ does not exist.
+ CategoryInfo : ObjectNotFound: (HKU:String) [Remove-Item], DriveNotFoundException
+ FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
+ PSComputerName : clt64792

By default, only the following PowerShell drives referencing registry locations are defined:

PS> Get-PSDrive -PSProvider Registry

Name Used (GB) Free (GB) Provider Root CurrentLocation
—- ——— ——— ——– —- —————
HKCU Registry HKEY_CURRENT_USER
HKLM Registry HKEY_LOCAL_MACHINE

You have to define HKU: before you can use it.
# Define drive HKU:
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
# Now you can use HKU:\… paths

Or, you can use provider prefix registry:: with the native registry path, which is simpler for ad-hoc use:

# E.g.
Get-ChildItem registry::HKEY_USERS\.DEFAULT

Below, please find a sample command:

Invoke-Command -ComputerName $inputPC -ScriptBlock {
Remove-Item ‘registry::HKEY_USERS\S-1-5-25\Software\Microsoft\Windows\CurrentVersion\RunOnce’
}