Trying to make a script to backup specific folders and then rename the GUID key for the target user under HKLM...\ProfileLists but the rename-item command makes a copy of the key and creates a new key with the appended name though having full access
Tried with -force, tried with move-item instead of rename but it gives the exact same results, a new identical key as original but with an appended name
if ((Test-Path $FULLPATH)) {
Rename-Item $FULLPATH -NewName "$SSID.bak" -Force
if ($?) {
Write-Host "$USERNAME was SUCCESSFULLY renamed in the registry"
}
}
Expected result is to only rename the GUID-key in the registry. Actual result is a duplicate key with the new duplicate to have the correct appended name.
Rename-Item : The registry key at the specified path does not exist. At line:9 char:5 + Rename-Item $FULLPATH -NewName "$SSID.bak" -Force + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (HKEY_LOCAL_MACH...\folderredirect:String) [Rename-Item], ArgumentException + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.RenameItemCommand
Rename-Item : Object reference not set to an instance of an object. At line:9 char:5 + Rename-Item $FULLPATH -NewName "$SSID.bak" -Force + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Rename-Item], NullReferenceException + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.RenameItemCommand
The key does exist and I can run the same command again as proof (due to the test-path).
Verbose output do confirm its copying
VERBOSE: Performing the operation "Copy Key" on target "the key in question"