Building a PowerShell script to remove OneDriveSetup from the registry. Each time I attempt to unload the UserHive, I get an "Error: Access is denied."
How am I unable to unload this hive?
##### Remove OneDriveSetup from Registry
$regHKUPath = "HKU:\UserHive\Software\Microsoft\Windows\CurrentVersion\Run"
$element = "C:\Users\Default"
$hideMe = New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS
$hideMe = reg load HKU\UserHive "$element\NTUSER.DAT"
If (Get-ItemProperty -Path $regHKUPath -Name OneDriveSetup -ErrorAction SilentlyContinue) {
Write-Output 'OneDriveSetup Value exists'
Get-Item -Path $regHKUPath | Remove-ItemProperty -Name OneDriveSetup
} Else {
Write-Output 'OneDriveSetup Value DOES NOT exist'
}
[gc]::Collect()
$hideMe = reg unload HKU\UserHive
$hideMe = Remove-PSDrive -Name HKU
##### End Remove OneDriveSetup from Registry