Simple 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).
Kris
Posts: 375
Joined: Wed May 12, 2010 3:22 am

Simple Powershell script

Post by Kris »

Hi, I try to run the following powershell command as a shell script:
Search-Adaccount -LockedOut | Measure | Select -Property Count | ft -Hide
In powershell this returns the number of locked AD accounts.

However, I can't get it to return any results in HM.

I use the following start cmd:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe %Script%
What am I missing here?
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Any script, used with Shell Script test, should return value in the following format:
ScriptRes:Ok:Reply text

You may try to change script the following way:

Code: Select all

$statusOk          = "ScriptRes:Ok:"
$statusBad         = "ScriptRes:Bad:"

$inf = Search-Adaccount -LockedOut | Measure | Select -Property Count | ft -Hide
echo $statusOk$inf
You may find several PowerShell script samples in Script Manager.

Please check for details at:
http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell
Kris
Posts: 375
Joined: Wed May 12, 2010 3:22 am

Post by Kris »

Hmm... no luck yet....

Code: Select all

[4:48:13 PM] HostMonitor is going to execute "PowerShell: # Locked users" script ...
[4:48:14 PM] Script started, no results received
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Could you try the following script:

Code: Select all

$statusOk  = "ScriptRes:Ok:" 
$statusBad = "ScriptRes:Bad:" 

Import-Module ActiveDirectory
$inf = (Search-Adaccount -LockedOut | Measure).Count
echo $statusOk$inf
Kris
Posts: 375
Joined: Wed May 12, 2010 3:22 am

Post by Kris »

Same result :-?

Does this work on your end?
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Could you please check if the following command:
echo (Search-Adaccount -LockedOut | Measure).Count
works connrectly on 32bit and 64bit Powershell versions?
Default locations for 32bit and 64bit powershell are:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe

If command works well on both powershells,
there may be some problems with Windows Pipe.
You may tell HostMonitor do not use Windows Pipe - add
SScript_UseWindowsPipe=0 line into [Misc] section of hostmon.ini file and restart HostMonitor.
Kris
Posts: 375
Joined: Wed May 12, 2010 3:22 am

Post by Kris »

Works with both version.

The Windows Pipe entry was already there in the hostmon.ini file.

Restarted HM to be sure, still no joy....
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

We have tested script on Windows Server 2008 R2 SP1 with HostMonitor 9.58 started as Application and Service started under BUILD-IN Administartor account. SScript_UseWindowsPipe=0 option is not present in hostmon.ini

What HostMonitor version do you use?
HostMonitor started as Application or Service?
Do you get this error using RCC "Lets try" tab or using HostMonitor GUI?
What Windows version and Service pack do you use? UAC enabled?
Kris
Posts: 375
Joined: Wed May 12, 2010 3:22 am

Post by Kris »

I get this message in both the "Let's try" tab and the gui.

HM 9.59 as application
W2K8R2 SP1
UAC disabled
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Could you try the following simple powershell script for testing:
echo "ScriptRes:Ok:Test Ok"

Start CMD: powershell.exe %script%
Kris
Posts: 375
Joined: Wed May 12, 2010 3:22 am

Post by Kris »

Code: Select all

[1:30:36 PM] Script started, no results received
:-?
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Could you try to change SScript_UseWindowsPipe parameter value in hostmon.ini and restart HostMonitor to:
SScript_UseWindowsPipe=1
Gavin
Posts: 58
Joined: Thu Sep 24, 2009 8:44 am

Post by Gavin »

This is what I have in start cmd under the test to run powershell scripts

c:\Windows\Sysnative\windowspowershell\v1.0\powershell.exe %script% %params%

I've had no issue with this running anywhere.
Kris
Posts: 375
Joined: Wed May 12, 2010 3:22 am

Post by Kris »

KS-Soft Europe wrote:Could you try to change SScript_UseWindowsPipe parameter value in hostmon.ini and restart HostMonitor to:
SScript_UseWindowsPipe=1
Done that.
This revealed the real problem: Execution Policy settings!
In PS I ran "Set-ExecutionPolicy Unrestricted", and everything works now :)

Should I set the "SScript_UseWindowsPipe" back to 0 again?
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

By default, HostMonitor uses Windows Pipes (SScript_UseWindowsPipe=1 or option is absent).
If all Shell Script test items work well, it's better to leave SScript_UseWindowsPipe=1 option or remove it from hostmon.ini.
Post Reply