Cannot load powershell module failkoverclusters in System Center Orchestrator Runbook

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.
LVL 2
itniflAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HankinaterCommented:
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

0
itniflAuthor 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#?
0
HankinaterCommented:
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.
0
HankinaterCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
itniflAuthor 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> }.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.