# set all explorer views for THIS logged on user globally to a special mode ...
# Use: 1 = Details, 2 = Tiles, 3 = Icons, 4 = List, 5 = Content

$ViewMode=1

write-host '#######',(split-path $PSCommandPath -Leaf),'#######'

# Paths for PowerShell commands use the registry Get-PSDrives, hence the ':'
$src = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes'
$dst = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes'
$topViews = "$dst\*\TopViews\*"

# Paths for reg.exe commands do not use a ':'
$bagMRU   = 'HKCR\Local Settings\Software\Microsoft\Windows\Shell\BagMRU'
$bags     = 'HKCR\Local Settings\Software\Microsoft\Windows\Shell\Bags'
$defaults = 'HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Streams\Defaults'

# Delete saved views and 'Apply to folders' defaults
write-host 'deleting Explorer saved views ...'
reg delete $bagMRU /f 2>&1 | Out-Null
reg delete $bags /f 2>&1 | Out-Null
reg delete $defaults /f 2>&1 | Out-Null
reg delete ($dst.Replace(':','')) /f 2>&1 | Out-Null

# First, we copy HKLM\...\FolderTypes to HKCU\...\FolderTypes
write-host 'copying HKLM folder types to HKCU ...'
Copy-Item $src "$(Split-Path $dst)" -Recurse

# Set all 'LogicalViewMode' values to the desired style
write-host 'setting explorer styles ...'
Get-ChildItem $topViews | % {

  $key2edit = (get-item $_.PSParentPath).OpenSubKey($_.PSChildName, $True);
  $key2edit.SetValue('LogicalViewMode', $ViewMode)

  # delete ANY "GroupBy" mode in any folder of explorer ...
  $key2edit.SetValue('GroupBy','')

  $key2edit.Close()

}

write-host 'restarting explorer ...'
Get-Process Explorer | ? {$_.SI -eq (Get-Process -PID $PID).SessionId} | Stop-Process -Force

write-host '#######',(split-path $PSCommandPath -Leaf),'#######'

