Problem with powershell script

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
Gavin
Posts: 58
Joined: Thu Sep 24, 2009 8:44 am

Problem with powershell script

Post by Gavin »

HM: 9.38

I'm having an issue with a script output with scriptres reporting the wrong result. If I run this code directly on the server with powershell when $backup_test_pass = $false and the rest equal true it echos the correct response of "Error: Exchange DB Not backed up". If I run this through Shell Script, it outputs "Error: Exchange DB Not Backed up | Database not mounted | Mapi Connectivity Fail |" Here is the portion of the code that is doing this. For some reason when run through hostmonitor some of the variables are evaluating as false when they should evaluate as true. Script works fine ran directly in powershell.

Code: Select all

if ($backup_test_pass -eq $false -or $mounted_test_pass -eq $false -or $queue_count_test_pass -eq $false -or $mapi_connectivity_test_pass -eq $false)
	{
		$final_error = "Error: "
		if ($backup_test_pass -eq $false)
			{
				$final_error = $final_error += "Exchange DB Not Backed up | "
			}
		if ($mounted_test_pass -eq $false)
			{
				$final_error = $final_error += "Database not mounted | "
			}
		if ($queue_count_test_pass -eq $false)
			{
				$final_error = $final_error += "Too many items in queue | "
			}
		if ($mapi_connectivity_test_pass -eq $false)
			{
				$final_error = $final_error += "MAPI Connectivity Fail | "
			}
		echo $statusbad$final_error
	}
elseif ($backup_test_pass -eq $true -and $mounted_test_pass -eq $true -and $queue_count_test_pass -eq $true -and $mapi_connectivity_test_pass -eq $true)
	{
		echo $statusok
	}
else
	{
		echo $statusunknown
	}
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

You should check code that assigns values to these variables ($backup_test_pass, $mounted_test_pass, ...)

What Windows do you use? Service Pack? UAC enabled? HostMonitor started as service? application?

Regards
Alex
Gavin
Posts: 58
Joined: Thu Sep 24, 2009 8:44 am

Post by Gavin »

Hi Alex,

The code is fine. When I run it as a normal script it outputs the correct values that I should see.

This is SBS 2008 (so effective Server 2008 SP2) and HostMonitor is running as an application as I am currently setting the tests up!
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

The code is fine.
What can we say if we do not see the code?
IMHO If code does not work correctly, then its not fine :roll:
When I run it as a normal script it outputs the correct values that I should see.
This is SBS 2008 (so effective Server 2008 SP2)
HostMonitor is running as an application
64bit system, right?
Then "normal" script in this case use 64 bit version of powershell. While HostMonitor starts 32bit version.
May be your code does not work in 32bit version. E.g. it may work incorrectly if you are using some Exchange extenstions because there are no 32bit version of components...
You may try to start 64bit powershell using command line like c:\Windows\Sysnative\windowspowershell\v1.0\powershell.exe ....

Regards
Alex
Gavin
Posts: 58
Joined: Thu Sep 24, 2009 8:44 am

Post by Gavin »

That fixed it Alex - working fine now. Might be worth adding something in as a default script example in the script manager for 64 bit Powershell.

I tell you what would be handy while I'm on the script manager - a bigger window or the ability to resize it.

Thanks for your time, Alex!
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

You are welcome.
That fixed it Alex - working fine now. Might be worth adding something in as a default script example in the script manager for 64 bit Powershell.
May be...
I tell you what would be handy while I'm on the script manager - a bigger window or the ability to resize it.
Don't see any problem, you can resize this window.

Regards
Alex
Post Reply