[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Cannot load powershell module failkoverclusters in System Center Orchestrator Runbook

Posted on 2014-08-30
5
Medium Priority
?
1,485 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.
0
Comment
Question by:itnifl
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:Hankinater
ID: 40300813
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
 
LVL 2

Author Comment

by:itnifl
ID: 40300876
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
 
LVL 2

Expert Comment

by:Hankinater
ID: 40300921
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
 
LVL 2

Accepted Solution

by:
Hankinater earned 2000 total points
ID: 40300927
0
 
LVL 2

Author Closing Comment

by:itnifl
ID: 40311433
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

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
This tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question