Nesting Modules in Manifest

Welcome Forums General PowerShell Q&A Nesting Modules in Manifest

This topic contains 7 replies, has 3 voices, and was last updated by

11 months, 2 weeks ago.

  • Author
  • #89938

    Points: 1
    Rank: Member


    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 –

    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's not recognizing them.

    Source code is located on GitHub –

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

    Thank you!

  • #90122

    Points: 1,704
    Helping HandTeam Member
    Rank: Community Hero

    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?

    • #90160

      Points: 1
      Rank: Member

      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'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....

    • #90163

      Points: 1
      Rank: Member

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

  • #90197

    Points: 324
    Helping Hand
    Rank: Contributor

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




    • #90202

      Points: 1
      Rank: Member

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

      VERBOSE: Importing alias 'New-SCOMManagementGroupConnection'.

  • #90652

    Points: 1
    Rank: Member

    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.
    –OperationsManager folder (portable cmdlets)

    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?

    • #90815

      Points: 1
      Rank: Member

      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.

      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"

The topic ‘Nesting Modules in Manifest’ is closed to new replies.