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 profile directory of the current logged-in user. I have also seen examples that assume all user profiles are saved in C:\Users\ and iterate/filter over that folder.
However, profile folders can be moved on Windows. My aim is to find (robustly) the profile directory of a specific user, given either that user's username (string) or a LocalUser object.
I can get an array of User objects based on active accounts with-
$users = Get-LocalUser | Where-Object Enabled -eq true
But the properties of those LocalUser objects are limited, and the UserProfile path is not among them. I believe this information is stored in the registry. I've through the PowerShell docs multiple times, but I haven't yet found the correct incantation that will give me the path of a user profile for a given user, which I can use in a loop to iterate across all users and their profile folders.