Search code examples
powershellpowershell-modulemicrosoft-file-explorer

File Explorer won't display PowerShell Modules directory otherwise visible in $env:psmodulepath


I'm in the process of learning how to create powershell modules through this youtube tutorial https://www.youtube.com/watch?v=yKstEJKdc4o&t=3661s - the video itself is not important.

I learned from learn.microsoft.com that powershell will have the following module directories by default:

$PSHome\Modules (%Windir%\System32\WindowsPowerShell\v1.0\Modules)

$Home\Documents\WindowsPowerShell\Modules (%UserProfile%\Documents\WindowsPowerShell\Modules)

$Env:ProgramFiles\WindowsPowerShell\Modules (%ProgramFiles%\WindowsPowerShell\Modules)

however there is no C:\users\john\Documents\WindowsPowerShell\Modules folder visible in File Explorer, while it's clearly visible in $env:psmodulepath when I run this from PowerShell. I'm able to navigate all the way to C:\Users\john\Documents\WindowsPowerShell but there is no Modules directory. I did enable hidden folders display and did also check Documents folders for OneDrive, Public, Administrator users. This is not a work/school computer, this is my own PC.

Can someone please help me understand why this Modules folder is visible in $env:psmodulepath but not in File Explorer?


Solution

  • Just because a location exists in $env:psmodulepath, doesn't mean it actually has to exists in the file system.

    You can add any random location to $env:psmodulepath without it actually existing. PowerShell will just skip any locations that don't exist.

    With a fresh Windows account, there isn't even a WindowsPowerShell directory under $env:userprofile\documents, to use a user profile or modules you have to create those directories.

    It is fairly easy for a user to create a new directory, but a little bit more tricky to add a new entry to $env:psmodulepath. I guess that is why they already put it in there, even though it may never be used.