2

I'm very new to PowerShell and have not administered Windows in a while. I have downloaded the Windows Update PowerShell module zip (http://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc) and put it in C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WindowsUpdate. PowerShell is not finding these modules.

I don't want to store them in my User's directory. I want them to be in the same directories as all the other stock PS modules.

slm
  • 7,615
  • 16
  • 56
  • 76
linuxadmin
  • 51
  • 1
  • 1
  • 3
  • 2
    Watch this video. At 5:35, they tell you NOT to put your modules there. *THE* architect of Powershell is telling you - do not put your modules there. Do not put your modules there. http://channel9.msdn.com/Series/advpowershell3/09 (PS Don't put your modules there.) – Ryan Ries Aug 15 '13 at 01:03
  • @RyanRies Where should system-wide non-Microsoft modules live? Disclaimer: Started at 5:35, couldn't take much of the blad dude's jokes. Snover was doing a good job of humoring him though. – jscott Aug 15 '13 at 01:14

2 Answers2

4

Your question indicates you extracted to:

C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WindowsUpdate

This is not the correct directory. The module is named PSWindowsUpdate, and as such, should be in a directory named PSWindowsUpdate. I extracted the zip to:

C:\Windows\System32\WindowsPowerShell\v1.0\Modules\PSWindowsUpdate

The following imports the module and works as expected:

Import-Module PSWindowsUpdate

jscott
  • 24,484
  • 8
  • 79
  • 100
1

As in the video that I posted in the comment to your original question, you shouldn't put your modules in the same place where Microsoft puts their modules. (i.e., C:\Windows\System32\WindowsPowershell\v1.0\Modules)

So where should you put your custom Powershell modules? The answer is simple. You put your modules in one of the directories specified in your PSModulesPath environment variable, that isn't System32\WindowsPowershell\v1.0\Modules.

PS C:\Users\ryan> $Env:PSModulePath -split ';'
C:\Users\ryan\Documents\WindowsPowerShell\Modules
C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
C:\Program Files (x86)\Microsoft SQL Server\110\Tools\PowerShell\Modules\

Now I know that you only see a user-specific directory up there. But you can add whatever path you want to this environment variable. And you can do it machine-wide, so that it affects all users. You can do this in the GUI by going to Advanced System Properties, or you can do it on the command line using setx. The set command is only good for the current session, setx will set a persistent, system-wide variable.

You could also try putting the PS module in

C:\Users\All Users\Documents\WindowsPowershell\Modules

But I haven't tested that so you might still need to add an environment variable for that directory.

Edit: Lastly, don't forget to create a subdirectory your module, so if your module is named Foo, you need to create the subdirectory Foo under one of those PSModulePaths.

Enjoy your Powershell learning journey! :)

Ryan Ries
  • 55,481
  • 10
  • 142
  • 199
  • Sometimes I am looking so closely at a problem I don't see the *obvious* answer -- `%PSModulePath%`, `$env:PSModulePath` was right there all along. Thanks for clarifying what I should have already known. :) – jscott Aug 16 '13 at 11:46