Nesting Modules in Manifest

Hello,

I’m attempting to nest the Operations Manager manifest/module into a custom module. I’ve organized the OpsMgr module to make it portable per this post - http://stholo.blogspot.com/2013/08/make-scom-2012-ps-module-portable.html

The OpsMgr folder is located under the private folder of the module (.\Private\OperationsManager\PowerShell\OperationsManager). In the main module, I’ve tried dot sourcing the OpsMgr manifest and/or module. I’ve also specified the OpsMgr manifest in the “NestedModules” section of the main manifest. Importing the main manifest with the verbose switch appears that all of the OpsMgr cmdlets are being imported, however when run…it’s not recognizing them.

Source code is located on GitHub - https://github.com/jmattivi/PSConfigMgr

Any help to get in the right direction is much appreciated!

Thank you!
Jon

Sorry for taking so long to reply on this. Holidays.

When you say, “not working,” what do you mean? Do you mean that you’re unable to run the OpsMgr command independently once your “outer” module is loaded?

No worries!

Correct. The “main” module functions include cmdlets from the OpsMgr module. Importing the “main” module with the verbose switch indicates that the OpsMgr cmdlets are being loaded. However, when the functions call the OpsMgr cmdlets…it’s saying they’re not recognized.

Importing the main manifest which references the OpsMgr manifest in the nestedmodules section -

VERBOSE: Importing cmdlet ‘New-SCManagementGroupConnection’.

Running one of the functions which calls the OpsMgr cmdlets -
The term ‘New-SCOMManagementGroupConnection’ is not recognized as the name of a cmdlet…

I also tested that the portable OpsMgr cmdlets work as intended. Importing that independently/explicitly, I’m able to run the cmdlets successfully.

Not sure if it’s a post issue, but your verbose output shows the function name missing an OM:

New-SCManagementGroupConnection

vs

New-SCOMManagementGroupConnection

Sorry…I copied the wrong line. It is loading the correct alias for the cmdlet.

VERBOSE: Importing alias ‘New-SCOMManagementGroupConnection’.

I’ve done a bit more testing…I’m still at a loss, but here are the results.

Here is how the module is laid out for testing.
root
-private
–OperationsManager folder (portable cmdlets)
-public
–Invoke-ConfigMgrSoftwareUpdates.ps1
–Start-OpsMgrMaintenanceMode.ps1

Here is the intended flow of the module and how it is “supposed” to work running Invoke-ConfigMgrSoftwareUpdates.
Invoke-ConfigMgrSoftwareUpdates calls Start-OpsMgrMaintenanceMode. Start-OpsMgrMaintenanceMode includes the cmdlets from the
OperationsManager module (New-SCOMManagementGroupConnection).

The above fails with “The term ‘New-SCOMManagementGroupConnection’ is not recognized…”

Running Start-OpsMgrMaintenanceMode directly runs successfully and executes the opsmgr cmdlets from the private module.

So it seems that calling the Start-OpsMgrMaintenanceMode function from another function breaks the underlying cmdlets. Is this a scope issue?

I finally figured this out. I originally was breaking out multiple functions from a PS workflow into this new module. The issue turned out to be the workflow calling the function and not importing the OpsMgr cmdlets explicitly to use in that session (not really anything to do with nesting the OpsMgr module).

Importing the modules explicitly as below, everything works as expected.

InlineScript
{
Import-Module "$using:PSWorkflowRoot\Private\Start-OpsMgrMaintenanceMode.ps1"
Import-Module "$using:PSWorkflowRoot\Private\OperationsManager\PowerShell\OperationsManager\OperationsManager.psd1"
Start-OpsMgrMaintenanceMode -ServerName $using:Server -Minutes 15 -Comment "Patching"
}