PowerShell 7.3 - how to Find User Profile Path when Using Get-ChildItem in User's Home Directory
I keep running into I'm trying to implement After trying multiple solutions online, I still can't figure this out... I'm working with an scenario trying to get the user profile path from the home directory. I am using PowerShell 7.3 on Windows 11, and my goal is to list all the files in a user's Documents folder by accessing it through the environment variable `$env:USERPROFILE`. However, when I run the following code: ```powershell $documentsPath = Join-Path $env:USERPROFILE 'Documents' Get-ChildItem -Path $documentsPath ``` I receive the behavior: `Get-ChildItem : want to find path 'C:\Users\[username]\Documents' because it does not exist.` I have verified that the user profile does exist and I can navigate to the path using File Explorer. I also checked the value of `$env:USERPROFILE`, which returns `C:\Users\[username]` as expected. To troubleshoot, I tried using the `Test-Path` cmdlet: ```powershell $documentsPath = Join-Path $env:USERPROFILE 'Documents' Test-Path -Path $documentsPath ``` This returned `False`, indicating that the path is not recognized. I also attempted using the `Get-Location` cmdlet to ensure I was in the correct directory before executing `Get-ChildItem`, but the location seems correct. I considered the possibility of permissions issues, but I have the necessary access rights to that directory. Are there any known bugs with PowerShell 7.3 in resolving user profile paths, or am I missing something in my approach? Any help would be appreciated! My development environment is macOS. What's the best practice here? Any feedback is welcome! This is my first time working with Powershell 3.11. How would you solve this?