Powershell script not running correctly from HM

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
jbarrellon
Posts: 23
Joined: Wed Oct 08, 2008 2:13 am

Powershell script not running correctly from HM

Post by jbarrellon »

Hello,

We're having about the same problem that described in this topic :

http://www.ks-soft.net/cgi-bin/phpBB/vi ... powershell

HM v9.58 running on a Windows Server 2008 R2
RMA v4.62 running on a Windows Server 2008 R2

When executing Powershell script locally on the remote server, it's working correctly and displaying correct result.
When executing from HM as a Shell Script with command line :
cmd /c powershell %Params% , the result is not the same (and not the good one).

Adding parameter SScript_UseWindowsPipe=1 in [Misc] section of rma.ini (and restarting rma) didn't work for us. We also tried this parameter in hostmon.ini (and restarted HM) but no more success.

Also, we don't get the complete reply in HM, for example :
in the script :
return "ScriptRes:Warning:Verifier que le role et les fonctionnalites 'Windows Server Backup' sont bien installees sur ce serveur"
in HM reply : Verifier que le role et les fonctionnalites 'Windows Server B
I don't know if this is related but i find it very strange.

here is the script :

Code: Select all

# Script pour voir le statut du job Windows Server Backup

# Launch script with force option
#Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -force

# Import du module Server Manager
Import-Module ServerManager

# Si la version de Windows est 2008 ou 2012
if ([Environment]::OSVersion.version.major -eq 6)
{
    # Windows 2012
    if ([Environment]::OSVersion.version.minor -gt 1)
    {
        $WSBFeatureBackup = Get-WindowsFeature | Where-Object {$_.Name -eq "Windows-Server-Backup"}
        $WSBFeatureTools = Get-WindowsFeature | Where-Object {$_.Name -eq "Migration"}
        $Winver = "2012"
    }
    # Windows 2008
    else
    {
        $WSBFeatureBackup = Get-WindowsFeature | Where-Object {$_.Name -eq "Backup"}
        $WSBFeatureTools = Get-WindowsFeature | Where-Object {$_.Name -eq "Backup-Tools"}
        $Winver = "2008"
    }
    # Vérification que les fonctionnalités sont bien installées
    If ($WSBFeatureBackup.Installed -and $WSBFeatureTools.Installed -eq "True")
    {
        # Si Windows 2008
        if ($Winver -eq "2008")
        {
            # Vérification que le module Windows.ServerBackup est importé
            if ( (Get-PSSnapin -Name Windows.ServerBackup -ErrorAction SilentlyContinue) -eq $null )
            {
                # Import du module Windows.ServerBackup
                Add-PsSnapin Windows.ServerBackup
            }
        }

        # Vérification de la présence d'un job de sauvegarde
        $WSBVerifJob = (Get-WBSummary).NumberOfVersions
        if ($WSBVerifJob -ne 0)
        {  
            # Vérification du statut de la sauvegarde
            $BackupResult = (Get-WBSummary).LastBackupResultHR
            if ($BackupResult -eq 0)
            {
                return "ScriptRes:Ok:Sauvegarde NAS OK"
            }
	        else
	        {
                return "ScriptRes:Bad:Erreur Sauvegarde NAS"
	        }
        }
        else
	    {
            return "ScriptRes:Warning:Verifier qu'un job de sauvegarde est bien présent sur ce serveur"
	    }
    }
    else
    {
        return "ScriptRes:Warning:Verifier que le role et les fonctionnalites 'Windows Server Backup' sont bien installees sur ce serveur"
    }
}
else
{
    return "ScriptRes:Warning:Ce script n'a pas ete teste pour cette version de Windows" 
}
Please let me know if you need aditional informations

Thanks in advance for your help
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

1. There are 2 Powershell version on 64bit OS (32bit and 64bit Powershell).
You could start 64bit powershell console and test script using 64bit console,
while HostMontior can start 32bit powershell (by default). That's why you may get different script results.
In order to check what exactly powershell are you currently using, you may use the following command/script:

Code: Select all

if ([System.IntPtr]::Size -eq 4) { "ScriptRes:Ok:32-bit" } else { "ScriptRes:Ok:64-bit" }
In order to use 64bit Powershell in HostMonitor, change Start cmd in Script Manager to:
C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe %script% %params%

2. Windows 2008 powershell modifies output by splitting it into lines after string riches console width. That's why HostMonitor shows "cutted" reply text.
You may add the following command at the beginning of the script in order to allow more characters (500) to be outputed without splitting into lines:
$Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size (500, 25)
jbarrellon
Posts: 23
Joined: Wed Oct 08, 2008 2:13 am

Post by jbarrellon »

2. Thank you very much, this is working.


1. This is working as well, however we absolutely don't understand why because :

- we thought that the command line in Start cmd was run by RMA as is, just like if we run it manually on the remote server (connected with the same account used for RMA). Where and how is it specified in RMA that it has to call 32 bits Powershell ?

- the new command line you provided : C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe %script% %params%, which is working, calls powershell in a directory that does not exist !
We've checked several times, directory C:\Windows\sysnative cannot be found neither in HM server nor in RMA server (even after activating visualisation of hidden files/directories and and system files/directories)

For aditional information, the way we're using Shell Script (for PowerShell tests at least) is the following : there is nothing in Script text area, our script is located on the remote server and the directory to call it is in Params text area, so we actually just call : C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe %params%
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Sysnative is a special alias, please check Microsoft manuals for details, e.g.
https://msdn.microsoft.com/en-us/librar ... s.85).aspx

Regards
Alex
jbarrellon
Posts: 23
Joined: Wed Oct 08, 2008 2:13 am

Post by jbarrellon »

Thank you for these details and thank you for your help.

Regards,
Julien
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

You are welcome!
Post Reply