Import-Module into Powershell 2.0

by OliAdams at 2013-04-04 14:58:46

I am trying to import a module I have made into powershell 2.0 and I am getting the error "The module manifest could not be processed because it is not a valid powershell restricted language file. The module imports fine into Powershell v 3.0. Where am I going wrong?

Thanks
by DonJ at 2013-04-04 22:42:58
Manifests changed slightly from v2 to v3. How did you produce the manifest? Using New-ModuleManifest in v2 should produce a valid manifest for v2/v3.

Also, in what kind of session are you attempting to import the module? The error is implying you’re in a session with restricted language features - so it might depend a bit on exactly what’s in the manifest.
by OliAdams at 2013-04-06 04:18:22
I created a module manifest using the tool and now the module imports which is great. However once imported no items appear under ExportedCommands: here is the output:

ModuleType Name ExportedCommands
---------- ---- ----------------
Manifest OATools


My Script looks like this:

function Get-OASystemInfo{…}

Export-ModuleMember -Function Get-OASystemInfo

Thanks in advance for any ideas.
by DonJ at 2013-04-06 05:01:30
Can you run your Get-OASystemInfo command once the module is imported? Does the manifest list any commands to export?
by OliAdams at 2013-04-06 05:10:16
No I the command is not found. The OATools.psd1 manifest contains the following lines.

# Functions to export from this module
FunctionsToExport = ‘'

# Cmdlets to export from this module
CmdletsToExport = '


I have also tried changing it to

# Functions to export from this module
FunctionsToExport = ‘Get-OASystemInfo’

and separately

# Cmdlets to export from this module
CmdletsToExport = ‘Get-OASystemInfo’

Although I thought this should not be needed as it is covered by Export-ModuleMember.
by DonJ at 2013-04-06 05:23:55
Weird. The only time I know I’ve seen that is when the module has a syntax error someplace, and can’t be parsed by the shell. I’m assuming you’ve saved the script as a normal .ps1, removed the Export-ModuleMember command from it, and tried to dot-source it to make sure it runs?
by OliAdams at 2013-04-06 05:44:59
yes I have been using the script for a week for testing and it works fine. I have also changed the psm1 back to a ps1 file and tested that aswell and it runs fine.
by DonJ at 2013-04-06 05:50:35
Can you post a copy as an attachment here?
by OliAdams at 2013-04-06 06:09:57
I added a value into the Root Module section and now it works fine, is that just user error on my part? I would of thought with Export-ModuleMember that should still of worked?
by DonJ at 2013-04-06 06:21:14
Ah. No, that’s the manifest. Without RootModule, the manifest doesn’t know what to load. So the manifest loads, which shows the module as being loaded, but your PSM1 didn’t load, so no commands. If you read the help for New-ModuleManifest, -RootModule is about the only parameter that actually loads any script files. The -ModuleList parameter (maybe you used that?) is just informational - it doesn’t actually load anything.
by OliAdams at 2013-04-06 06:30:13
Ok thanks it all makes sense I just went through and entered all the information the command required when run. I would of thought the root module parameter would of been mandatory. It is working now so thanks for the guidance.
by OliAdams at 2013-04-06 10:12:20
I have tried to import the module onto my production machine which is powershell 2 and I get the following error. The import works fine on version 3. Any ideas? is root module not supported on version 2?

Import-Module : The ‘C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\oatools\oatools.psd1’ module cannot be imported
because its manifest contains one or more members that are not valid. The valid manifest members are (‘ModuleToProcess
’, ‘NestedModules’, ‘GUID’, ‘Author’, ‘CompanyName’, ‘Copyright’, ‘ModuleVersion’, ‘Description’, ‘PowerShellVersion’,
‘PowerShellHostName’, ‘PowerShellHostVersion’, ‘CLRVersion’, ‘DotNetFrameworkVersion’, ‘ProcessorArchitecture’, ‘Requir
edModules’, ‘TypesToProcess’, ‘FormatsToProcess’, ‘ScriptsToProcess’, ‘PrivateData’, ‘RequiredAssemblies’, ‘ModuleList’
, ‘FileList’, ‘FunctionsToExport’, ‘VariablesToExport’, ‘AliasesToExport’, ‘CmdletsToExport’). Remove the members that
are not valid (‘RootModule’), then try to import the module again.
At line:1 char:14
+ Import-Module <<<< oatools
+ CategoryInfo : InvalidData: (C:\WINDOWS\syst…ls\oatools.psd1:String) [Import-Module], InvalidOperatio
nException
+ FullyQualifiedErrorId : Modules_InvalidManifestMember,Microsoft.PowerShell.Commands.ImportModuleCommand
by DonJ at 2013-04-06 10:22:04
Correct. That’s exactly what the error message says. Check out the help for New-ModuleManifest on your v2 machine.