Share via

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

Robert Groux 176 Reputation points
2021-08-13T18:10:37.013+00:00

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.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Andreas Baumgarten 131.4K Reputation points MVP Volunteer Moderator
    2021-08-15T17:01:39.053+00:00

    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. Stefan Horz 3,551 Reputation points
    2021-08-26T20:30:17.427+00:00

    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

  3. Andreas Baumgarten 131.4K Reputation points MVP Volunteer Moderator
    2021-08-16T16:06:46.967+00:00

    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


Your answer

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