Finding All Profiles with Desktop

by Mar 16, 2017

This simple line dumps all paths to all desktops found in any of the local user profiles – just make sure you are running the line with Administrator privileges to see other peoples‘ profiles:

Resolve-Path -Path C:\users\*\Desktop -ErrorAction SilentlyContinue

If you just would like to get the user names for those profiles that have a „Desktop“ folder, try this:

Resolve-Path -Path C:\users\*\Desktop -ErrorAction SilentlyContinue |
    ForEach-Object { 
        $_.Path.Split('\')[-2]
    }

The code takes the paths and splits them at the backslash, producing an array of path components. Index -2 is the second-last component, thus the name of the user.

Twitter This Tip! ReTweet this Tip!