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

Shell script gives wrong result

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



Joined: 16 Jul 2021
Posts: 22

PostPosted: Thu Oct 14, 2021 4:13 am    Post subject: Shell script gives wrong result Reply with quote

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



Joined: 03 Apr 2002
Posts: 12790
Location: USA

PostPosted: Thu Oct 14, 2021 4:58 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
BoschmanIT



Joined: 16 Jul 2021
Posts: 22

PostPosted: Thu Oct 14, 2021 8:07 am    Post subject: Reply with quote

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



Joined: 03 Apr 2002
Posts: 12790
Location: USA

PostPosted: Thu Oct 14, 2021 9:42 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
BoschmanIT



Joined: 16 Jul 2021
Posts: 22

PostPosted: Fri Oct 15, 2021 12:43 am    Post subject: Reply with quote

Hi Alex,

by Sysnative you mean the System32 folder?
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12790
Location: USA

PostPosted: Fri Oct 15, 2021 3:49 am    Post subject: Reply with quote

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/windows/win32/winprog64/file-system-redirector

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



Joined: 16 Jul 2021
Posts: 22

PostPosted: Fri Oct 15, 2021 5:26 am    Post subject: Reply with quote

Hi Alex,

I never knew the existence of this feature. It solved the problem. Thank you very much.
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12790
Location: USA

PostPosted: Fri Oct 15, 2021 5:43 am    Post subject: Reply with quote

You are welcome

Regards
Alex
Back to top
View user's profile Send private message 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