question

RobertGroux avatar image
0 Votes"
RobertGroux asked StefanHorz answered

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

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
       
 }


msc-orchestrator
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
1 Vote"
AndreasBaumgarten answered RobertGroux edited

Hi @RobertGroux ,

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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @AndreasBaumgarten

Thanks for taking the time to answer this.

To answer your questions. We are on Orchestrator 10.19.40.0. Orchestrator is using Powershell version: 5.1.17763.1971. I did test just now on 32bit and that appears to be the issue. The modules require 64bit. I did make the changes you suggested and it appears to run successfully. The only issue I'm having now is that nothing is actually done. I'm getting a successful run message but it should take about 10 or 15 minutes to run this command and it finishes with a matter of seconds.

I will say the command output does produce some errors. Essentially what I'm doing is adding a bunch of computers to a group. If the computers already exist in the group an error will be thrown. Could this be causing the script to "Crash" but show it as ran successful?


edit: I tested your code with powershell.exe { code here } in the ISE 32bit and still get the error. Is there anyway to execute with a module that uses 64bit? I've tried a few things online like Invoke-Command and others but wasn't able to get them working.

0 Votes 0 ·
AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered AndreasBaumgarten commented

Hi @RobertGroux ,

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




image.png (81.5 KiB)
image.png (61.2 KiB)
image.png (26.9 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @RobertGroux ,

are there any additional questions? Does the answer help to solve the issue?
If you found the answer helpful, it would be great if you please mark it "Accept as answer". This will help others to find answers in Q&A


Regards
Andreas Baumgarten

0 Votes 0 ·
StefanHorz avatar image
0 Votes"
StefanHorz answered

Hi @RobertGroux ,

you get no error with correct explanation and tip from @AndreasBaumgarten , 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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.