We help IT Professionals succeed at work.

Cannot load powershell module failkoverclusters in System Center Orchestrator Runbook

1,833 Views
Last Modified: 2014-09-09
When I run the sctript below it works in normal powershell on the system center orchestrator server, but not in a runbook in system center orchestrator itself. I get: "The term 'Get-Cluster' 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."

. E:\scripts\GetFillingDegree.ps1

$ClusterName = "clusternamegoeshere";
$fillingDegree = 0;
$a = GetFillingDegree $ClusterName
$fillingDegree = $a.fillingDegree;

Open in new window


Here is the GetFillingDegree function located in GetFillingDegree.ps1:
Function GetFillingDegree {
	param([string] $ClusterName)

	Import-Module 'E:\scripts\Virtual Machine Manager\bin\psModules\virtualmachinemanagercore\virtualmachinemanagercore.psd1'
	Import-Module 'E:\scripts\Virtual Machine Manager\bin\psModules\virtualmachinemanager\virtualmachinemanager.psd1'
	Import-Module 'C:\Windows\System32\WindowsPowerShell\v1.0\Modules\FailoverClusters\FailoverClusters.psd1'
#I have also tried just: Import-Modules FailoverClusters which works in normal powershell but not in Orchestrator
	
	$props = @{
		errorlevel= 0;
    }

	[array] $cNodes = Get-Cluster $ClusterName|Get-ClusterNode |Where {$_.state -eq "Up"} |Select Name
	$nodecount = $cNodes.length
	[array] $hostDetails = Get-Cluster $ClusterName|Get-ClusterNode|Select name, @{Label="TotalPhysicalMemory"; Expression={[int]""}}, @{Label="AvailablePhysicalMemory"; Expression={[int]""}}, @{Label="AvailablePhysicalMemoryPC"; Expression={[int]""}}, @{Label="TotalVMStartupRamAllocated"; Expression={[int]""}}, @{Label="TotalVMMaxMemoryAllocated"; Expression={[int]""}}, @{Label="Processors"; Expression={[int]""}}, @{Label="ProcessorCore"; Expression={[int]""}}, @{Label="LogicalProcessors"; Expression={[int]""}}, @{Label="vProcessors"; Expression={[int]""}}, @{Label="HostMemoryHealth"; Expression={[int]""}}, @{Label="VMs"; Expression={[int]""}}
	For ($i=0; $i -lt $nodecount; $i++) {
		#Write-Host ("Processing Hyper-V Host "+$cNodes.Name[$i]) -Foregroundcolor Green -BackgroundColor DARKGREEN
		$hDetails = Get-WmiObject -Class win32_OperatingSystem -ComputerName $cNodes.Name[$i] |Select FreePhysicalMemory, TotalVisibleMemorySize
		[int] $hostDetails[$i].TotalPhysicalMemory =  ((($hDetails).TotalVisibleMemorySize)/1048576)
		[int] $hostDetails[$i].AvailablePhysicalMemoryPC  =  (((($hDetails).FreePhysicalMemory)/(($hDetails).TotalVisibleMemorySize))*100)
		[int] $hostDetails[$i].AvailablePhysicalMemory =  ((($hDetails).FreePhysicalMemory)/1048576)
		If (($hostDetails[$i].AvailablePhysicalMemoryPC -le "10") -OR ($hostDetails[$i].AvailablePhysicalMemory -lt "5"))
			{
			[int] $hostDetails[$i].HostMemoryHealth = "3"
			}
		ElseIf ((($hostDetails[$i].AvailablePhysicalMemoryPC -le "20") -And ($hostDetails[$i].AvailablePhysicalMemoryPC -gt "10")) -OR (($hostDetails[$i].AvailablePhysicalMemory -lt "10") -And ($hostDetails[$i].AvailablePhysicalMemory -gt "5")))
			{
			[int] $hostDetails[$i].HostMemoryHealth = 2
			}
		ElseIf ((($hostDetails[$i].AvailablePhysicalMemoryPC -le "30") -And ($hostDetails[$i].AvailablePhysicalMemoryPC -gt "20")) -OR (($hostDetails[$i].AvailablePhysicalMemory -lt "20") -And ($hostDetails[$i].AvailablePhysicalMemory -gt "10")))
			{
			[int] $hostDetails[$i].HostMemoryHealth = 1
			}
		Else
			{
			[int] $hostDetails[$i].HostMemoryHealth = 0
			}
		$procDetails = Get-WmiObject -Class Win32_Processor -Computername $cNodes.Name[$i]
		$hostDetails[$i].Processors = ($procDetails.DeviceID).Count
		$hostDetails[$i].ProcessorCore = ($procDetails.numberofcores |Measure-Object -Sum).sum
		$hostDetails[$i].LogicalProcessors = ($procDetails.numberoflogicalprocessors |Measure-Object -Sum).sum
	}
	$TotalPhysicalMemory = 0
	$AvailablePhysicalMemory = 0
	$hostDetails | % {
		$TotalPhysicalMemory += $_.TotalPhysicalMemory
		$AvailablePhysicalMemory += $_.AvailablePhysicalMemory
	}
	
	$fillingDegree = 1-$AvailablePhysicalMemory/$TotalPhysicalMemory	
	$props.Add("fillingDegree", $fillingDegree);	

	return new-object PSCustomObject –property $props
}

Open in new window


To be able to load any of the modules at all I used this guide:
http://tameyourcloud.com/?p=170
That took care of the "Could not load file or assembly" error I originally had, but I am now left with the error I described above here.
Comment
Watch Question

Have you tried moving the Import-Module to the top of the script?

Like this?

Import-Module 'E:\scripts\Virtual Machine Manager\bin\psModules\virtualmachinemanagercore\virtualmachinemanagercore.psd1'
Import-Module 'E:\scripts\Virtual Machine Manager\bin\psModules\virtualmachinemanager\virtualmachinemanager.psd1'
Import-Module 'C:\Windows\System32\WindowsPowerShell\v1.0\Modules\FailoverClusters\FailoverClusters.psd1'

Function GetFillingDegree {
	param([string] $ClusterName)

	#I have also tried just: Import-Modules FailoverClusters which works in normal powershell but not in Orchestrator
	
	$props = @{
		errorlevel= 0;
    }

Open in new window

itniflProgrammer

Author

Commented:
Still get the error:
"The term 'Get-Cluster' 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."

Running the whole thing via powershell instead of powershell via System Center Orchestrator, and the whole thing runs nicely and returns what I would expect. But just not in Orchestrator. Obviously, Orcherstrator is not using the same environment. What is it about that? I find no guides for handeling powershell in relation to Orchestrator, but obviously, it is an issue. Maybe I am better off writing an integration pack in c#?
Yeah, I've had issues like that as well with Orchestrator.  Most times I use Run .Net  Script activity.  Sometimes when I have that issue I run the script using Run Command activity and kick it off that way.  The only caveat is that you get the output in one shot.  

I have had some success with Execute PS Script activity, but again you'll get the output as one clump of information.

You might try having your script export it to a CSV file.  You can then use that CSV in a separate PowerShell script to grab the data the way you want it.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
itniflProgrammer

Author

Commented:
From your link:

2. To run in a V3, 64-bit PowerShell environment, use C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe { <your code> }.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.