You can retrieve the root (parent) directory of all user profile directories from the registry as follows:

$profilesRootDir = 
  Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList' ProfilesDirectory

To get a specific user's profile directory, say jdoe, you can then use:

# See more robust alternative below.
Join-Path $profilesRootDir jdoe

However, the ultimate source of truth is the ProfileImagePath value in the subkeys of the above registry key path, named for each user's SID (security identifier), which Get-LocalUser does provide (the output objects have a .SID property).

Thus, it is better to use:

Get-ItemPropertyValue "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$((Get-LocalUser jdoe).SID)" ProfileImagePath

To reliably get the profile directories of all enabled local users, use the following:

Get-LocalUser | 
  Where-Object Enabled |
  ForEach-Object {
    # Note the use of ...\ProfileList\_.SID) and value name ProfileImagePath
    Get-ItemPropertyValue "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\_.SID)" ProfileImagePath
  }
Answer from mklement0 on Stack Overflow
🌐
Reddit
reddit.com › r/powershell › get userprofile path for current logged in user.
r/PowerShell on Reddit: Get userprofile path for current logged in user.
May 28, 2021 -

Hello Powershellers

In my current environment, there are several users who’s profile folder name is different than their username due to AD changes. So I’m looking for a way to find the profile path of the logged in user and I can’t necessarily rely on the username. The other twist is that the power shell script is run by third party software and I’m not sure which service it runs as because $env:Userprofile variable doesn’t work when using the software. Any other ideas on how I can do this? My end goal is to copy a shortcut that is under a users profile to the startup folder.

Top answer
1 of 3
2

You can retrieve the root (parent) directory of all user profile directories from the registry as follows:

$profilesRootDir = 
  Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList' ProfilesDirectory

To get a specific user's profile directory, say jdoe, you can then use:

# See more robust alternative below.
Join-Path $profilesRootDir jdoe

However, the ultimate source of truth is the ProfileImagePath value in the subkeys of the above registry key path, named for each user's SID (security identifier), which Get-LocalUser does provide (the output objects have a .SID property).

Thus, it is better to use:

Get-ItemPropertyValue "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$((Get-LocalUser jdoe).SID)" ProfileImagePath

To reliably get the profile directories of all enabled local users, use the following:

Get-LocalUser | 
  Where-Object Enabled |
  ForEach-Object {
    # Note the use of ...\ProfileList\_.SID) and value name ProfileImagePath
    Get-ItemPropertyValue "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\_.SID)" ProfileImagePath
  }
2 of 3
1

Perhaps something along this line:

$users = Get-LocalUser | Where-Object Enabled -eq true

$profilesRootDir = @(
 Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList' ProfilesDirectory)

ForEach ($User in $Users) {

  $UserPath = Join-Path -Path "$profilesRootDir" -ChildPath "$User"

  "User     : $User`n" +
  "User-Path: $UserPath" 
}

Output:

User     : Bruce
User-Path: C:\Users\Bruce
🌐
Business.com
business.com › home › technology › it management
A Guide to Managing User Profiles With PowerShell
February 12, 2026 - Get-WmiObject -Class Win32_UserProfile -ComputerName ‘MEMBERSRV1′,’CLIENT2’
🌐
Reddit
reddit.com › r/powershell › how do i pull the logged in userprofile and not the running profile?
r/PowerShell on Reddit: How do I pull the logged in userprofile and not the running profile?
March 25, 2023 -

I am working on a script to install Epicor.exe through PowerShell. I am using $desktopPath = "$($env:userprofile)\Desktop" for part of this script but instead of going to the logged on user's desktop it is going to the user desktop of the person running the script. I.E. If an admin runs this, it will go to the admins desktop.

$env:username will take the username of whatever account is running the script, it will not get the logged in user.

Top answer
1 of 4
1
$ErrorActionPreference = "SilentlyContinue"$Path = "C:\Users"$UserFolders = Get-ChildItem -Path $Path -Directory$currentDate = Get-Date$ageLimit = 60# Set the execution policy to bypass (use with caution in production)Set-ExecutionPolicy Bypass -Force# Loop through each user profile folderForEach ($UserFolder in $UserFolders) {    $UserName = $UserFolder.Name    # Only process profiles that have an NTUser.dat file    $NTUserPath = "$Path\$UserName\NTUSER.DAT"    If (Test-Path $NTUserPath) {        $Dat = Get-Item $NTUserPath -Force        $DatTime = $Dat.LastWriteTime        # Reset NTUSER.DAT's LastWriteTime to match the folder's LastWriteTime        If ($UserFolder.Name -ne "default") {            $Dat.LastWriteTime = $UserFolder.LastWriteTime        }    }    # Calculate profile age and delete if older than $ageLimit    $profileAge = ($currentDate - $UserFolder.LastWriteTime).Days    If ($profileAge -ge $ageLimit) {        # Remove user profile and any content inside it (use with caution)        Try {            Remove-Item -Path $UserFolder.FullName -Recurse -Force            Write-Host "Deleted profile: $UserName"        } Catch {            Write-Host "Error deleting profile: $UserName - $_"        }    }}# Optional: Clean up empty folders (if necessary)$EmptyFolders = Get-ChildItem -Path $Path -Directory | Where-Object { $_.GetFileSystemInfos().Count -eq 0 }ForEach ($EmptyFolder in $EmptyFolders) {    Try {        Remove-Item -Path $EmptyFolder.FullName -Force        Write-Host "Deleted empty folder: EmptyFolder.Name)"    } Catch {        Write-Host "Error deleting empty folder: EmptyFolder.Name) - $_"    }}Write-Host "Profile cleanup complete."
2 of 4
0
Your script is on the right track for deleting old user profiles, but there are a few improvements that can make it more efficient, avoid some pitfalls (such as leaving empty folders), and potentially clean up obsolete or unnecessary parts of the code. Here's an enhanced version of the script, with some optimizations and added checks:Suggestions & Improvements:Use -Directory when getting user profiles: You can directly filter for directories with -Directory in the Get-ChildItem cmdlet, reducing the need for additional checks.Ensure NTUser.dat exists: You don't need to call Get-Item multiple times in a loop if you can check for existence first. I’ve added that check with Test-Path.Handle empty profile folders: When a profile folder is removed, we should check if it’s empty before attempting to remove it. If it's empty, you can remove it with Remove-Item as well.Use -Force for visibility of hidden files: This ensures hidden files like NTUser.dat are also handled properly.Remove the report object: If you're not using $Report, it can be omitted.Ensure execution policy is set before script runs: It’s more logical to set the execution policy at the start, so it’s enforced before running any other script actions.
🌐
Microsoft
devblogs.microsoft.com › dev blogs › scripting blog [archived] › powertip: use powershell to find user profile path
PowerTip: Use PowerShell to Find User Profile Path - Scripting Blog [archived]
February 19, 2014 - Summary: Use Windows PowerShell to find the user profile path. How can I easily get information about the folder and path to the profile for a currently signed-in user? Use the Env: PowerShell drive, and select the UserProfile environmental variable: $env:USERPROFILE
Find elsewhere
🌐
Rene Nyffenegger
renenyffenegger.ch › notes › Windows › dirs › Users › username › index
%USERPROFILE%
PS C:\> ls $env:USERPROFILE PS C:\> ls $home PS C:\> ls ~ PS C:\> cd ~ PS C:\> cd ~/Documents · Thus, the tilde seems to mimic the function it also has in bash. A possible way to determine the path of a user's profile in PowerShell is like so:
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.core › about › about_profiles
about_Profiles - PowerShell | Microsoft Learn
September 29, 2025 - The following command determines whether an "All Users, All Hosts" profile has been created on the local computer: ... For example, to create a profile for the current user in the current PowerShell host application, use the following command:
🌐
PowerShell Gallery
powershellgallery.com › packages › Get-UserProfile › 1.0.7 › Content › Get-UserProfile.psm1
PowerShell Gallery | Get-UserProfile.psm1 1.0.7
This site uses cookies for analytics, personalized content and ads. By continuing to browse this site, you agree to this use. Learn more · Get-UserProfile · 1.0.7 · Get-UserProfile.psm1 · Contact Us · Terms of Use · Gallery Status · Feedback · © 2026 Microsoft Corporation
🌐
GitHub
gist.github.com › crshnbrn66 › 7e81bf20408c05ddb2b4fdf4498477d8
PowerShell functions to create a new user profile · GitHub
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Remove-Profile
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › scripting › learn › shell › creating-profiles
Customizing your shell environment - PowerShell | Microsoft Learn
November 21, 2025 - PS> $PROFILE | Select-Object * AllUsersAllHosts : C:\Program Files\PowerShell\7\profile.ps1 AllUsersCurrentHost : C:\Program Files\PowerShell\7\Microsoft.PowerShell_profile.ps1 CurrentUserAllHosts : C:\Users\username\Documents\PowerShell\profile.ps1 CurrentUserCurrentHost : C:\Users\username\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 Length : 69 · The following command shows the default profile locations on Ubuntu Linux.
🌐
Stack Overflow
stackoverflow.com › questions › 63362870 › powershell-script-to-find-userprofile-and-change-directory-to-the-profile
powershell script to find userprofile and change directory to the profile - Stack Overflow
Let's make it powershell: Set-Location "$($env:UserProfile)\Desktop" netsh interface show interface >.\nicreset.txt netsh interface ip show config >>.\nicreset.txt netstat -ano >>.\nicreset.txt netstat -r >>.\nicreset.txt netstat -b -v >>.\nicreset.txt netstat -s >>.\nicreset.txt nbtstat -R >>.\nicreset.txt ipconfig /flushdns >>.\nicreset.txt ipconfig /registerdns >>.\nicreset.txt notepad.exe ".\nicreset.txt"
🌐
PowerShell Forums
forums.powershell.org › powershell help
${Env:USERPROFILE} in administrator shell - PowerShell Help - PowerShell Forums
February 4, 2016 - Hello Powershell users. I have a script that will be running on local accounts on different machines, but the script itself needs admin privileges to run properly. The problem is that I need to use environment variables like ${USERPROFILE}, so the path will be correct on the current logged in user.
🌐
LazyAdmin
lazyadmin.nl › home › how to create a powershell profile – step-by-step
How to Create a PowerShell Profile - Step-by-Step — LazyAdmin
May 17, 2024 - The first step in creating your own profile is to test if you already have a profile. Open PowerShell and type: ... You can use the same method to create the profile of all hosts or all users using the command in the table above.
🌐
Powershell Commands
powershellcommands.com › powershell-userprofile
Mastering the PowerShell UserProfile: A Quick Guide
May 27, 2024 - To access the UserProfile information quickly, PowerShell utilizes built-in environment variables. The most pertinent variable for accessing the UserProfile path is `$env:USERPROFILE`. You can retrieve it using the following command:
🌐
Microsoft
devblogs.microsoft.com › dev blogs › scripting blog [archived] › use powershell to find user profiles on a computer
Use PowerShell to Find User Profiles on a Computer - Scripting Blog [archived]
November 10, 2011 - Here are the aliases the following command uses: ... Here is the code to get the user profiles, convert the time from WMI format to a regular date time value, and display the path and SID: ... CW, that is all there is to finding profiles on a computer. Join me tomorrow for more cool Windows PowerShell stuff.