How do I install and import the Powershell Community Extensions for a normal user?
I want to use Powershell as my Visual Studio Command Prompt and have found that the route to doing this is via the Powershell Community Extensions but I am having trouble installing and importing Pscx.
From a normal (i.e. not run as Administrator) Powershell prompt; if I run Install-Module Pscx
I get the error
Administrator rights are required to install modules in 'C:\Program Files\WindowsPowerShell\Modules'. Log on to the computer with an account that has Administrator rights, and then try again, or install 'D:\Documents\WindowsPowerShell\Modules' by adding "-Scope CurrentUser" to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator).
I took the suggestion and tried running Install-Module Pscx -Scope CurrentUser
, which reported no errors. But then when I run Import-Module Pscx
I get the error
The specified module 'Pscx' was not loaded because no valid module file was found in any module directory.
After running Remove-Module Pscx
I ran a Powershell prompt as administrator where I was able to install and import Pscx but having done so I can still not import it from a non-admin Powershell prompt. My final attempt was (in the admin prompt) to remove the module and install it again with -Scope AllUsers
but this still gives the same error when I try to Import-Module Pscx
in a non-admin prompt.
I have been a developer for 30+ years but every time I try to do something in Powershell it makes me feel stupid. Despite all the great documentation, I just don't find it easy to use. Can someone please help me get past this current misery. I don't just want to solve the problem but also try to understand what is happening in the hope it that it will help me reach that place where I can actually understand why Powershell is behaving in a seemingly strange manner that makes little sense to me.
My version of Powershell is 5.0, build 10586, revision 494.
I have figured out what the problem was.
Install-Module
with -Scope CurrentUser
installs the module in the %USERPROFILE%\Documents\WindowsPowerShell\Modules
folder but this folder is not included in the PSModulePath environment variable, hence Import-Module
can't find the module. Once I figured this out I add the following to my profile so I won't be caught out by this again.
if ($env:PSModulePath -notlike "*D:\Documents\WindowsPowerShell\Modules*")
{
$env:PSModulePath = $env:PSModulePath + ";D:\Documents\WindowsPowerShell\Modules"
}
Notice that while my %USERPROFILE%
is C:\Users\SteveC
I have moved my Documents folder from my SSD C drive to my HDD D drive so %USERPROFILE%\Documents
resolves to D:\Documents
.
- Download Pscx package from CodePlex
- Paste the unzipped Pscx in C:\WINDOWS\System32\WindowsPowerShell\v1.0\Modules
- Open Powershell Editor ISE as Administrator
- Run
Install-Module Pscx -AllowClobber
- Done