Skip to content

Instantly share code, notes, and snippets.

@avoidik
Created October 20, 2022 06:34
Show Gist options
  • Save avoidik/f47099fef11db6624129f829a7fcc5dc to your computer and use it in GitHub Desktop.
Save avoidik/f47099fef11db6624129f829a7fcc5dc to your computer and use it in GitHub Desktop.
Change Windows known shell folders

List all

$knownFolders = Get-Item 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders'
foreach ($folder in $knownFolders) {
    $props = Get-ItemProperty $folder.PSPath
    foreach ($p in $props.PSObject.Properties) {
        Write-Host "$($p.Name) = $($p.Value)"
    }
}

Replace all based on a condition

$knownFolders = Get-Item 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders'
foreach ($folder in $knownFolders) {
    $props = Get-ItemProperty $folder.PSPath
    foreach ($p in $props.PSObject.Properties) {
        if ($p.Value -like "C:\Users\Administrator\*") {
            $newValue = $($p.Value).Replace('C:\Users\Administrator\', 'X:\Data\Administrator\')
            Set-ItemProperty -Path $props.PSPath -Name $p.Name -Value $newValue
            # Get-ItemProperty -Path $props.PSPath -Name $p.Name
        }
    }
}

Note: this is highly not recommended approach, there is only one valid approach - sysprep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment