Not in front of a computer but something close to this run as administrator iirc. Get-Item "C:\Users\*\Desktop\Name Of Shortcut.lnk" | Remove-Item Answer from QuisitQ on reddit.com
🌐
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.

🌐
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
Discussions

UserProfile Management with PowerShell
We have an issue where quarterly Nessus scans enumerate vulnerability findings for every user profile on an endpoint. This started me on a path to remove... More on techcommunity.microsoft.com
🌐 techcommunity.microsoft.com
4
0
November 6, 2024
powershell - Correct way to access the USERPROFILE dir of a specific user in a script? - Stack Overflow
I'm writing a script to perform some file operations in the USERPROFILE folder of each (local) user on a Windows machine. I have found various examples that use $env:USERPROFILE to identify the pro... More on stackoverflow.com
🌐 stackoverflow.com
Get userprofile path for current logged in user.
If $env:USERPROFILE doesn't work, is this because the software you're using is running using either SYSTEM or a service account? Also, give this a read . Enumerating the HKEY_USERS registry hive might be the way to go. More on reddit.com
🌐 r/PowerShell
18
May 28, 2021
${Env:USERPROFILE} in administrator shell
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. More on forums.powershell.org
🌐 forums.powershell.org
5
0
February 4, 2016
🌐
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’
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.
🌐
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 $profile variable returns the profile for the current user in the current program (host). But as mentioned, there are different profiles. If you also work a lot in PowerShell ISE, then makes more sense to use the Current User – All Hosts ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.core › about › about_profiles
about_Profiles - PowerShell | Microsoft Learn
September 29, 2025 - This means that changes made in ... always runs last. In PowerShell Help, the CurrentUserCurrentHost profile is the profile most often referred to as your PowerShell profile....
Find elsewhere
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
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › scripting › learn › shell › creating-profiles
Customizing your shell environment - PowerShell | Microsoft Learn
November 21, 2025 - You can create profile scripts that run for all users or just one user, the CurrentUser. CurrentUser profiles are stored under the user's home directory path. The location varies depending on the operating system and the version of PowerShell ...
🌐
TechTarget
techtarget.com › searchwindowsserver › tutorial › How-to-find-and-customize-your-PowerShell-profile
How to find and customize your PowerShell profile | TechTarget
The PowerShell profile is simply a PowerShell script that runs every time you launch PowerShell, except when you launch PowerShell with the -NoProfile flag.
Published   September 16, 2025
🌐
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:
🌐
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.

🌐
GitHub
gist.github.com › crshnbrn66 › 7e81bf20408c05ddb2b4fdf4498477d8
PowerShell functions to create a new user profile · GitHub
PowerShell functions to create a new user profile. GitHub Gist: instantly share code, notes, and snippets.
🌐
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
🌐
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.
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › powershell tutorials › how to create and manage powershell profile?
How to Create and Manage PowerShell Profile? - SharePoint Diary
October 3, 2025 - A PowerShell profile is a script that runs whenever you start a PowerShell session. It allows you to customize your PowerShell environment by setting aliases, functions, variables, and more.
🌐
PowerShell Gallery
powershellgallery.com › packages › SysAdminTools › 1.1.30 › Content › Public\Get-UserProfile.ps1
PowerShell Gallery | Public/Get-UserProfile.ps1 1.1.30
September 23, 2021 - This site uses cookies for analytics, personalized content and ads. By continuing to browse this site, you agree to this use. Learn more · SysAdminTools · 1.1.30 · Public/Get-UserProfile.ps1 · Contact Us · Terms of Use · Gallery Status · Feedback · © 2026 Microsoft Corporation
🌐
Progress
progress.com › blogs › how-to-accurately-enumerate-windows-user-profiles-with-powershell
How To Enumerate Windows User Profiles With PowerShell
November 13, 2024 - PowerShell PS> Get-ChildItem 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion\ProfileList' | ForEach-Object { $profilePath = $_.GetValue('ProfileImagePath') Get-ChildItem -Path "$profilePath\AppData\Local\Temp" }