question

SachinPakhare-6676 avatar image
0 Votes"
SachinPakhare-6676 asked MotoX80 commented

Intermittently executing powershell file via powershell.exe fails with error 65536

Hi Team,

Recently we are intermittently facing issues while running the Powershell file via powershell.exe. This exists with error code 65536. The call to run the Powershell file is triggered by the console application.

The same command works perfectly fine with Powershell version 4.0. We have never faced any issue using that.

Powershell version:
Name Value


PSVersion 5.1.17763.1852
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.1852
CLRVersion 4.0.30319.42000

Operating System: Windows Server 2019

Script:
$Key = "HKLM:\SOFTWARE\TestApp"
$Value = "TestKey"

If (Test-Path $Key) {
(Get-ItemProperty -Path $Key).$Value
}

Note: The issue is intermittently failing for different scripts. Nothing specifically to the above script.

Can someone please help?

Thanks!!

windows-server-powershellwindows-server-2019
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Can you provide the full error message?

0 Votes 0 ·

Hi @IanXue-MSFT,

The weird thing is when I launch this from my console application (written in C++), I get an error message as just "W". But as I said this happens intermittently.

0 Votes 0 ·

1 Answer

MotoX80 avatar image
0 Votes"
MotoX80 answered MotoX80 commented

Sorry, I don't fully understand what you are trying to say.

The call to run the Powershell file is triggered by the console application.

So you have a console application written in C# or VB.Net that calls Powershell.,exe to run this script? Or do you mean that Powershell.exe is the console application?


The issue is intermittently failing for different scripts. Nothing specifically to the above script.

Does this mean that you have multiple scripts that call the above script whose code you posted here?

Like this:

 # This is C:\Scripts\GetTestKey.ps1
 $Key = "HKLM:\SOFTWARE\TestApp"
 $Value = "TestKey"
    
 If (Test-Path $Key) {
      (Get-ItemProperty -Path $Key).$Value
 }

And

 # This is MainScript1.ps1
 # Other processing is done here.
 # Now call our GetKeyValue script.
 $KeyData = C:\Scripts\GetTestKey.ps1
 "The script returned {0}" -f $KeyData
 # Other processing is done here.

The best place to start would be to add a transcript to capture any errors that Powershell encounters. Like this:

     # This is MainScript1.ps1
     Start-Transcript -Path C:\Logs\MainScript.log -Append         # start logging here 
     # Other processing is done here.
     # Now call our GetKeyValue script.
     $KeyData = C:\Scripts\GetTestKey.ps1
     "The script returned {0}" -f $KeyData
     # Other processing is done here.
     Stop-Transcript                                                # stop logging. 



· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi MotoX80,

Yes, I have a console application written in C++ which is running the process "powershell.exe -file ps_file.ps1".

When I say I have multiple scripts like the above one. Each for a different purpose.

Sure I can try adding the transcript file. I will update you if I find anything here.

0 Votes 0 ·
MotoX80 avatar image MotoX80 SachinPakhare-6676 ·

Your program needs to capture both stdout and stderr. There should be an error message in there.

https://stackoverflow.com/questions/300669/launch-app-capture-stdout-and-stderr-in-c

0 Votes 0 ·

Yes, I capture both stdout & stderr. But the output I get is just "W" & the exit code 65536. Also, this is intermittent.

0 Votes 0 ·
Show more comments