KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Powershell script not running correctly from HM

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting
View previous topic :: View next topic  
Author Message
jbarrellon



Joined: 08 Oct 2008
Posts: 23

PostPosted: Tue Jun 16, 2015 8:04 am    Post subject: Powershell script not running correctly from HM Reply with quote

Hello,

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

http://www.ks-soft.net/cgi-bin/phpBB/viewtopic.php?t=6953&highlight=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:
# 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
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Tue Jun 16, 2015 1:50 pm    Post subject: Reply with quote

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:
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)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jbarrellon



Joined: 08 Oct 2008
Posts: 23

PostPosted: Fri Jun 19, 2015 4:06 am    Post subject: Reply with quote

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%
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12795
Location: USA

PostPosted: Fri Jun 19, 2015 4:32 am    Post subject: Reply with quote

Sysnative is a special alias, please check Microsoft manuals for details, e.g.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa384187(v=vs.85).aspx

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
jbarrellon



Joined: 08 Oct 2008
Posts: 23

PostPosted: Fri Jun 19, 2015 7:13 am    Post subject: Reply with quote

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

Regards,
Julien
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Fri Jun 19, 2015 7:15 am    Post subject: Reply with quote

You are welcome!
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index