List redirected user folders

Version: 4.1.8
Creator Name: Zeev Eisenberg
Date Created: 2014-06-23
Date Modified: 2016-06-15
Scripting language: PS
Download Count: 686

Script overview

Shows which folders are redirected for selected user session/s.

Script use case

Folder Redirection is a well-known mechanism which is widely used in multi-user environments. When a need arises to check whether a given live user session has user redirection policies applied to it, the task of verifying the current locations for the user folders can be challenging. The main reason for this is the fact that these locations can only be retrieved from inside the user session. This script-based action is executed in the live user session, enumerating all user shell folders which are redirected to non-default locations outside the user profile. This enables for an easy verification of any Folder Redirection policies applied to the user session and for a quick discovery of redirection-related issues.

Script output screenshot


Script URL

controlup://SBA/list redirected user folders
Tags: Folder Redirection, User Shell Folders, PowerShell, Folder Enumeration,

The Script

Function Get-RegistryKeyPropertiesAndValues
{
  <#
    This function is used here to retrieve registry values while omitting the PS properties
    Example: Get-RegistryKeyPropertiesAndValues -path 'HKCU:\Volatile Environment'
    Origin: Http://www.ScriptingGuys.com/blog
    Via: http://stackoverflow.com/questions/13350577/can-powershell-get-childproperty-get-a-list-of-real-registry-keys-like-reg-query
  #>

 Param(
  [Parameter(Mandatory=$true)]
  [string]$path
  )

  Push-Location
  Set-Location -Path $path
  Get-Item . |
  Select-Object -ExpandProperty property |
  ForEach-Object {
      New-Object psobject -Property @{"Folder"=$_;
        "RedirectedLocation" = (Get-ItemProperty -Path . -Name $_).$_}}
  Pop-Location
}

# Get the user profile path, while escaping special characters because we are going to use the -match operator on it
$Profilepath = [regex]::Escape($env:USERPROFILE)

# List all folders
$RedirectedFolders = Get-RegistryKeyPropertiesAndValues -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" | Where-Object {$_.RedirectedLocation -notmatch "$Profilepath"}
if ($RedirectedFolders -eq $null) {
    Write-Output "No folders are redirected for this user"
} else {
    $RedirectedFolders | format-list *
}