Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

System Center Orchestrator runbook activity returns wrong number

Posted on 2014-10-06
1
Medium Priority
?
151 Views
Last Modified: 2015-01-17
The runbook looks like this:
RunbookThe return data step returns the $Degree variable returned from the script activity.

The script activity looks like this and returns the value from the $Degree variable:
Script Activity
The GetFillingDegree.ps1 script looks like this:
Function GetFillingDegree {
	param([string] $ClusterName)

	Import-Module FailoverClusters
	
	try {
		$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
		}
		if(!$TotalPhysicalMemory -or $TotalPhysicalMemory -eq 0) {
			$TotalPhysicalMemory = 1;
		}
		$fillingDegree = 1-($AvailablePhysicalMemory/$TotalPhysicalMemory);
	} catch {
		throw @("ERROR: 1 Could not AOS-GetFillingDegree:" + $_.Exception.ItemName + " - " + $_.Exception.Message)
	}
	$props.Add("fillingDegree", $fillingDegree);
	Write-Host $fillingDegree
	
	return $props
}

Open in new window


When the runbook is tested with the Orchestrator runbook tester the degree that is returned is the true number, for instance 0,8432234. If the script GetFillingDegree.ps1 is run from console, it returns the same number 0,8432234. But if the runbook is run from another runbook via "Invoke Runbook," it always returns 1. I tried to echo $fillingDegree in GetFillingDegree.ps1 to a file before it was returned from the function, and I could see the result was the same there as well. So the number is not being changed to 1 on the way to the runbook, through the runbook or when it is returned from it. It is 1 already in the GetFillingDegree.ps1 script, but only if the whole ordeal is started via the runbook activity from another runbook. How to fix?
0
Comment
Question by:itnifl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
itnifl earned 0 total points
ID: 40554998
The answer is very simple.
1.To read the cluster resources from the cluster, the user that runs the script must have access to do this on the cluster itself.
2. To use the Get-WmiObject cmdlet, the user running the script needs to have the appropriate access rights to run this cmdlet against the hosts that the cmdlet is running against(the cluster nodes).

When all this is done, all is good.

This would be easier to know if Orchestrator threw a access right violation error, but instead it somehow ends up with returning 1 every time. Not sure why that is, and I am not diving into it :)

Problem solved,
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Issue: One Windows 2008 R2 64bit server on the network unable to connect to a buffalo Device (Linkstation) with firmware version 1.56. There are a total of four servers on the network this being one of them. Troubleshooting Steps: Connect via h…
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

722 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