View previous topic :: View next topic |
Author |
Message |
BoschmanIT
Joined: 16 Jul 2021 Posts: 22
|
Posted: Thu Oct 14, 2021 4:13 am Post subject: Shell script gives wrong result |
|
|
Hi all,
I have a question. If I run the script below from the script manager it says
Quote: | [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: |
$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"} |
|
|
Back to top |
|
 |
KS-Soft
Joined: 03 Apr 2002 Posts: 12649 Location: USA
|
Posted: Thu Oct 14, 2021 4:58 am Post subject: |
|
|
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 |
|
Back to top |
|
 |
BoschmanIT
Joined: 16 Jul 2021 Posts: 22
|
Posted: Thu Oct 14, 2021 8:07 am Post subject: |
|
|
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. |
|
Back to top |
|
 |
KS-Soft
Joined: 03 Apr 2002 Posts: 12649 Location: USA
|
Posted: Thu Oct 14, 2021 9:42 am Post subject: |
|
|
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 |
|
Back to top |
|
 |
BoschmanIT
Joined: 16 Jul 2021 Posts: 22
|
Posted: Fri Oct 15, 2021 12:43 am Post subject: |
|
|
Hi Alex,
by Sysnative you mean the System32 folder? |
|
Back to top |
|
 |
KS-Soft
Joined: 03 Apr 2002 Posts: 12649 Location: USA
|
|
Back to top |
|
 |
BoschmanIT
Joined: 16 Jul 2021 Posts: 22
|
Posted: Fri Oct 15, 2021 5:26 am Post subject: |
|
|
Hi Alex,
I never knew the existence of this feature. It solved the problem. Thank you very much. |
|
Back to top |
|
 |
KS-Soft
Joined: 03 Apr 2002 Posts: 12649 Location: USA
|
Posted: Fri Oct 15, 2021 5:43 am Post subject: |
|
|
You are welcome
Regards
Alex |
|
Back to top |
|
 |
|