Monthly Archive

Categories

Module Manifests

When we looked at modules we used Export-Module at the end of the module file to control which functions were made visible.  This becomes a little awkward if we have a large number of functions that we may want to use in differing combinations.

The solution is to use a module manifest.  This is a file that looks something like this

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
#
# Module manifest for module 'user'
#
# Generated by: Richard Siddaway
#
# Generated on: 22/02/2009
#

@{
# These modules will be processed when the module manifest is loaded.
NestedModules = 'user.psm1'

# This GUID is used to uniquely identify this module.
GUID = 'b55021a4-5a21-4cf6-9b76-29eef95db0cf'

# The author of this module.
Author = 'Richard Siddaway'

# The company or vendor for this module.
CompanyName = 'Macdui'

# The copyright statement for this module.
Copyright = '(c) Richard Siddaway'

# The version of this module.
ModuleVersion = '1.0'

# A description of this module.
Description = 'Module of scripts for working with AD user accounts'

# The minimum version of PowerShell needed to use this module.
PowerShellVersion = '2.0'

# The CLR version required to use this module.
CLRVersion = '2.0'

# Functions to export from this manifest.
ExportedFunctions = 'new-password'

# Aliases to export from this manifest.
ExportedAliases = '*'

# Variables to export from this manifest.
ExportedVariables = '*'

# Cmdlets to export from this manifest.
ExportedCmdlets = '*'

# This is a list of other modules that must be loaded before this module.
RequiredModules = @()

# The script files (.ps1) that are loaded before this module.
ScriptsToProcess = @()

# The type files (.ps1xml) loaded by this module.
TypesToProcess = @()

# The format files (.ps1xml) loaded by this module.
FormatsToProcess = @()

# A list of assemblies that must be loaded before this module can work.
RequiredAssemblies = @()

# Lists additional items like icons, etc. that the module will use.
OtherItems = @()

# Module specific private data can be passed via this member.
PrivateData = ''

}

I generated this one on Windows 7.  Use New-Module manifest without any parameters and you will be prompted for the required information.  The rest can be filled in using your favourite editor.  The CTP3 version uses slightly different names in some places so the two aren’t completely compatible.

The manifest can be tested

PS> Invoke-History 59
Test-ModuleManifest ./user2.psd1

Name              : user2.psd1
Path              : C:\Scripts\wip\user2.psd1
Description       : Module of scripts for working with AD user accounts
Guid              : b55021a4-5a21-4cf6-9b76-29eef95db0cf
Version           : 1.0
ModuleBase        : C:\Scripts\wip
ModuleType        : Manifest
PrivateData       :
AccessMode        : ReadWrite
ExportedAliases   : {}
ExportedCmdlets   : {}
ExportedFunctions : {}
ExportedVariables : {}
NestedModules     : {}

Notice the use of invoke-history to rerun a previous command.

That is the basics of modules covered.  Next task is to add some functions and modify the manifest so that I can use it to create users

Technorati Tags: PowerShell,Modules

Leave a Reply