I remapped/changed the target/location of a few of my special folders using the windows explorer gui. Now some of my powershell scripts broke. I don't want to resort to hard-coding paths, unless I have to, and then, only as a temp fix.
[System.Environment]::GetFolderPath('Desktop')
shows the wrong path.
[System.Environment]::GetFolderPath('Downloads')
doesn't work.
To recreate: Right click on "Downloads" in the win explorer gui, and change target location to d:\downloads. Do the same for Desktop to something like d:\desktop.
According to Get Path To "Links" (AKA Favorites) Folder, there may be a way to P/Invoke SHGetKnownFolderPath
, but I am not versed in how to perform that, and botched attempts to date. However, I found Boe Prox' function, https://github.com/proxb/PInvoke/blob/master/Get-KnownFolderPath.ps1, which does use SHGetKnownFolderPath
, and that function does not show the remapped values for either desktop or downloads.
How would you access the remapped location using PowerShell?
UPDATE: To narrow things down, this issue seems to only impact Windows 7 (64-bit, 32-bit wasn't tested). The Get-KnownFolderPath.ps1 script reports correctly in Windows 10. PowerShell is v5 in all tests. How would one script access the remapped locations of both operating systems?