Share via

Command was found in the module but the module could not be loaded

Robert Groux 171 Reputation points
Aug 13, 2021, 6:10 PM

I'm trying to run a command from the OpsMgrExtended module: https://www.powershellgallery.com/packages/OpsMgrExtended/1.3.1 inside a .NET Script activity. Every time I execute this code I'm given the following error. This command works fine in ISE and normal powershell.

The term 'New-OMComputerGroupExplicitMember' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Below is the code I'm running that is redacted a bit

Import-Module -Name OperationsManage, OpsMgrExtended -verbose
New-SCOMManagementGroupConnection -ComputerName "scom.server"
$vms = import-csv C:\Scripts\computers.csv
$scom = 'scom.server'

foreach($vm in $vms)
{
    $server = $vm.VmName
    New-OMComputerGroupExplicitMember -SDK $scom -GroupName 'group.name' -ComputerPrincipalName $server

}
System Center Orchestrator
System Center Orchestrator
A family of System Center products that provide an automation platform for orchestrating and integrating both Microsoft and non-Microsoft IT tools.
242 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Andreas Baumgarten 116.3K Reputation points MVP
    Aug 15, 2021, 5:01 PM

    Hi @Robert Groux ,

    first some questions:
    Which version of Orchestrator are you running?
    Which version of PowerShell is used by Orchestrator? (https://get-cmd.com/?p=3731)
    Have you tested your script in a 32-bit PowerShell/ISE? Unfortunately Orchestrator is still using the 32-bit PowerShell in a .Net Script activity.

    Maybe you this helps:

    powershell.exe { Import-Module -Name OperationsManage, OpsMgrExtended -Verbose  
        New-SCOMManagementGroupConnection -ComputerName "scom.server"  
        $vms = Import-Csv C:\Scripts\computers.csv  
        $scom = 'scom.server'  
             
        foreach ($vm in $vms) {  
            $server = $vm.VmName  
            New-OMComputerGroupExplicitMember -SDK $scom -GroupName 'group.name' -ComputerPrincipalName $server  
                
        }  
    }  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    2 people found this answer helpful.

  2. Andreas Baumgarten 116.3K Reputation points MVP
    Aug 16, 2021, 4:06 PM

    Hi @Robert Groux ,

    please create a new Runbook for testing:

    123644-image.png

    $Result = Invoke-Command -ComputerName localhost {  
        $Is64Bit = [Environment]::Is64BitProcess  
        $PSVersion = $PSVersionTable.PSVersion  
        RETURN $Is64Bit, $PSVersion  
    }  
      
    $64bit = $Result[0]  
    $PSVersion = $Result[1]  
    

    123645-image.png

    Start the runbook in the Runbook Tester and should get the results like this (some lines deleted):

    123598-image.png

    If you get the same results like in my screenshot it's the latest PS Version and 64-bit Powershell.
    Than your code should work the same like in a 64bit ISE (if you use the Runbook Tester)

    $Result = Invoke-Command -ComputerName localhost {  
        Import-Module -Name OperationsManage, OpsMgrExtended -Verbose  
        New-SCOMManagementGroupConnection -ComputerName "scom.server"  
        $vms = Import-Csv C:\Scripts\computers.csv  
        $scom = 'scom.server'  
      
        foreach ($vm in $vms) {  
            $server = $vm.VmName  
            New-OMComputerGroupExplicitMember -SDK $scom -GroupName 'group.name' -ComputerPrincipalName $server  
      
        }  
    }  
    $Result  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


  3. Stefan Horz 3,466 Reputation points
    Aug 26, 2021, 8:30 PM

    Hi @Robert Groux ,

    you get no error with correct explanation and tip from @Andreas Baumgarten , because the error (perhaps permission) is in the invoked session, add this to get the error:

     powershell.exe { Import-Module -Name OperationsManage, OpsMgrExtended -Verbose  
         New-SCOMManagementGroupConnection -ComputerName "scom.server"  
         $vms = Import-Csv C:\Scripts\computers.csv  
         $scom = 'scom.server'  
                 
         foreach ($vm in $vms) {  
             $server = $vm.VmName  
             New-OMComputerGroupExplicitMember -SDK $scom -GroupName 'group.name' -ComputerPrincipalName $server  
                    
         }  
     }2>&1  
    IF ($Error) {throw New-Object System.Exception($Error)}  
    

    Best regards,
    Stefan

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.