In order to resolve a registry bloat issue caused by Samsung Print Drivers I'm needing to find a way to Export a user's Roaming Profile NTUSER.DAT Registry Hive while in PowerShell. Loading and Exporting a NTUSER.DAT Registry Hive works in REGEDIT, but so far I have not found a way to do this in PowerShell.
The PowerShell Script I am working on is able to Load the remote Registry Hive, remove keys, and unload. This does not provide a way for free/empty space to be removed from the Registry Hive file. When manually doing this in REGEDIT I've been able to take bloated NTUSER.DAT files that are over 150,000KB and then export them as a new NTUSER_Clean.DAT Registry Hive all the way down to 780KB (for a user with relatively few settings).
PowerShell Example code:
Write-Host "Attempting to load the User Roaming Profile Registry HIVE (NTUSER.DAT)." #Write-Host $strRemoteLocation reg load "HKU\$strKeyName" $strRemoteLocation Write-Host $strLine Write-Host "Attempting to clean the Registry HIVE of Samsung SSPrint Keys." Clean_Key $strKeyName "spd__" Clean_Key $strKeyName "spe__" Clean_Key $strKeyName "ssp6m" Write-Host $strLine # Export Registry HIVE to NTUSER_Clean.DAT Write-Host "This section would export the Registry HIVE to a new file." Write-Host "At this point I'm not sure how to do this." Write-Host $strLine # Unload the Registry HIVE Write-Host "Attempting to unload the Registry HIVE." [gc]::collect() start-sleep -s 3 reg unload "HKU\$strKeyName"
So far I have NOT found a way to use the reg (reg.exe) to Export as a Registry Hive file. The "reg EXPORT" argument only generates .reg files as far as I am aware.