One-Liner: Getting My Documents and Other Special Folders
I have roaming profiles, which is great until I need to reference stuff in my Documents folder. Sure, I can hardcode \\ProfilerServer10\Mydocs2\timdunn\My Documents into my script, but I want to make my scripts more reusable by my team members. The closest I’ve been able to find is
Split-Path –Parent –Path (Split-Path –Leaf –Path $Profile)
There’s still enough parse-by-prayer in there for me to be uneasy with it. Recently, I found this:
[Environment]::GetFolderPath("MyDocuments")
thanks to https://www.vistax64.com/powershell/19524-need-quick-way-get-my-documents-folder.html.
That’s really all about it. When I get a chance, I’ll move my unified profile to that folder instead of simply $HOME\WindowsPowerShell. Of course, I’ll need to change the $ProfileData:profileSystemFolder away from WindowsPowerShell, because that’s where $PROFILE actually lives.