@@ -18,6 +18,8 @@ import (
1818 "golang.org/x/text/transform"
1919)
2020
21+ const powershellVersionCheckCommand = "\" $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor)\" "
22+
2123func executeUsingPowershell (ctx context.Context , message * Message , device agent.Device , logger hclog.Logger ) []byte {
2224 // Parse the commands
2325 commandBytes , err := base64 .StdEncoding .DecodeString (message .Commands )
@@ -39,14 +41,14 @@ func executeUsingPowershell(ctx context.Context, message *Message, device agent.
3941 }
4042
4143 if logger .IsDebug () {
42- cmd := exec .CommandContext (ctx , shell , "-Command" , "\" $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor).$($PSVersionTable.PSVersion.Build).$($PSVersionTable.PSVersion.Revision)\" " )
43- outBytes , err := cmd .Output ()
44+ cmd := exec .CommandContext (ctx , shell , "-Command" , powershellVersionCheckCommand )
45+ combinedOutputBytes , err := cmd .CombinedOutput ()
46+ combinedOutput := string (combinedOutputBytes )
4447 if err != nil {
45- logger .Error ("Shell version check failed" , "error" , err )
46- return errorResultBytes (err )
48+ logger .Error ("Shell version check failed" , "error" , err , "combined_output" , combinedOutput )
4749 }
4850
49- version := strings .TrimSpace (string ( outBytes ) )
51+ version := strings .TrimSpace (combinedOutput )
5052
5153 logger .Debug ("Shell version" , "shell" , shell , "version" , version )
5254 logger .Debug ("Commands to execute" , "commands" , commands )
0 commit comments