Shell script gives wrong result

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
BoschmanIT
Posts: 24
Joined: Fri Jul 16, 2021 4:08 am

Shell script gives wrong result

Post by BoschmanIT »

Hi all,

I have a question. If I run the script below from the script manager it says
[12:05:58 ] Script executed, correct result received:
----------
- Status: Ok
- Reply:
----------
But that is wrong, It should result in Status: Bad and Reply: 151000. When I run powershell myself it does work just as expected and the output is correct.

Code: Select all

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

$Backlog = (Get-DfsrBacklog -DestinationComputerName "MyServerName" -SourceComputerName "MyOtherServerName" -GroupName "MyGroupName" -FolderName "MyFolderName" -verbose 4>&1).Message.Split(':')[2]
$Backlog = $Backlog.Trim()

if ($Backlog -ge 1){
    echo $statusBad" $Backlog"}
else {
    echo $statusOk" $Backlog"}
KS-Soft
Posts: 12846
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Status is Ok because $Backlog is empty.
Why $Backlog is empty? May be some permission related issue, script started under different accounts may provide different results.

You should modify your script, it should check for possible errors, set Unknown status in case of error and provide error message

Regards
Alex
BoschmanIT
Posts: 24
Joined: Fri Jul 16, 2021 4:08 am

Post by BoschmanIT »

Hi Alex,

I chopped it into pieces and the following result came back.

+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-DfsrBacklog:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
----------

When the shell script runs, does it use the powershell.exe from the operating system? Because it seems that whenever I run the Get-DfsrBacklog command, it does not seem to know the the command. But when I open powershell direcly (on the same server, and even as the same user that runs the HM service) powershell does know that command.
KS-Soft
Posts: 12846
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Some powershell commands work only in x64 version of powershell.
You should start powershell using path like
c:\Windows\Sysnative\windowspowershell\v1.0\powershell.exe

Regards
Alex
BoschmanIT
Posts: 24
Joined: Fri Jul 16, 2021 4:08 am

Post by BoschmanIT »

Hi Alex,

by Sysnative you mean the System32 folder?
KS-Soft
Posts: 12846
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

No. If you type system32, Windows will redirect system calls. Type sysnative
Sysnative - a special alias used to indicate that the file system should not redirect the access.
https://docs.microsoft.com/en-us/window ... redirector

Regards
Alex
BoschmanIT
Posts: 24
Joined: Fri Jul 16, 2021 4:08 am

Post by BoschmanIT »

Hi Alex,

I never knew the existence of this feature. It solved the problem. Thank you very much.
KS-Soft
Posts: 12846
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

You are welcome

Regards
Alex
Post Reply