tags:

views:

2182

answers:

5
+2  A: 

Here's a little bit of information. http://huddledmasses.org/powershell-modules/

http://blogs.msdn.com/mediaandmicrocode/archive/2008/08/10/microcode-all-about-modules-windows-powershell-ctp2.aspx

Let's hope that the upcoming CTP3 has some useful documentation about modules.

Martin
A: 

Windows PowerShell v2.0: TFM (sapienpress.com) has information and samples in one of the chapters. It's available as an ebook which is updated as new CTPs are released. I also blogged about them on ConcentratedTech.com, and there's been discussion on them at PowerShellCommunity.org in the forums.

Don Jones
A: 

Modules will hopefully solve a few problems. Right now, we can use dot sourcing to get functions, variables, and scripts into a PowerShell session's global scope.

The problem is that this can pollute your session with all kinds of global variables and helper functions that an end user may not want/need directly.

Modules will allow you as an author to build scripts and only make certain functions/variables avaiable to the end user of the module.

They also essentially replace the concept of a PSSnapin. You can use Add-Module Some.dll to add an assembly that has cmdlets in it.

What is really cool is what is called a Module Manifest. This is a hash table that basically specifies all kinds of dependcies as well as author, name, GUID Identifier, and version number. When a user loads a module that has a module manifest, it will check all the dependencies and run any scripts the module author deems necessary.

There should be some decent documentation on these when CTP3 ships.

Hope that helps a bit.

Andy

Andy Schneider
+2  A: 

With the Win7 build, Add-Module is gone. The new cmdlet is Import-Module. The easiest way to create a module is rename a PS1 file to a PSM1 file. From there you can do all sorts of things including the module manifest.

Andy Schneider
Import-Module doesn't work either. In fact there are no commands that have the word module in them:gcm | ?{$_.Name.Contains("Module")} | fl nameOh well I'll wait until CTP 3 to find out more!
Hainesy
+1  A: 

I'm no Powershell expert, but here's what I just figured out using PowerShell 2.0 RTM.

Suppose you want to create a module called MyModule:

  1. Make sure that you have created the folder %My Documents%\WindowsPowershell\Modules
  2. Create a folder inside Modules called MyModule
  3. Put your code in a file inside MyModule and name the file MyModule.psm1
  4. Remember to use the Export-ModuleMember command as the last thing in your script file. Export-ModuleMember -Function * -Alias * will export all functions and aliases
  5. In scripts where you want to use the module, use the command Import-Module MyModule

By default Powershell is configured not to run any kinds of scripts from files, so you need to alter the security settings. Set-ExecutionPolicy Unrestricted will get you going if you're not concerned about scripts needing to be signed.

Samuel Jack