0

I have been trying to write a script to automate software installation (IBM Spectrum Protect) for several days but I have a problem getting the output of an exe command.

This command aims to verify that the client is able to reach and is registered on the ISP server queried.

The most incomprehensible in all this is that all its commands work as expected on my dev VM (W2016 PS: 5.1.14393.5127) but not on my test VM (W2022 PS: 5.1.20348.859).

Was there a particular modification between W2016 / W2022 that would impact the processing of exe in powershell?

I tried several approaches. First I tried to capture the output to a file then read it (Get-Content) but all the commands return an empty file (same for the third one with Transcript, the file is filled with the usual comments from Transcript but the area reserved for commands remains empty...)

1st attempt:

$arg = "UPDATEPW /node:$env:COMPUTERNAME /password:$env:COMPUTERNAME /optfile:"$OptFile"" Start-Process "$InstallDir\baclient\dsmcutil.exe" -ArgumentList $arg -NoNewWindow -Wait -RedirectStandardOutput $OutputFile

2nd attempt:

& "$InstallDir\baclient\dsmcutil.exe" UPDATEPW /node:$env:COMPUTERNAME /password:$env:COMPUTERNAME /optfile:"$OptFile" | Out-File $OutputFile

3rd attempt:

Start-Transcript -Path $OutputFile Start-Process "$InstallDir\baclient\dsmcutil.exe" -ArgumentList $arg -NoNewWindow -Wait Stop-Transcript

Getting nowhere, I tried an interactive mode:

Start-Process -FilePath powershell -ArgumentList "-noexit -command (.\dsmcutil.exe UPDATEPW /node:$env:COMPUTERNAME /password:$env:COMPUTERNAME)" -WorkingDirectory "$InstallDir\baclient"

This command is supposed to display in a new powershell, prompt the result of the command and then I just ask the user if the command was successful or not. Unfortunately, the command does open a new command prompt but does not execute anything in it!!!

Thank you in advance for your help !

Regards.

Herunòla
  • 13
  • 2
  • Put script into a file with extension ps1. Then open a powershell window and execute the script >.\test.ps1 – jdweng Nov 21 '22 at 14:15
  • Still not working... – Herunòla Nov 22 '22 at 06:57
  • What errors are you getting? The Powershell should now be reporting errors that that you can see. I usually add debug statement to code to help determine where issues are occurring. I use "Write-Host $variable" and "$table | Format-Table" to help isolate issues. Often I find that code that works in c# fails in PowerShell because data type default to object where in c# object get case to defined types. – jdweng Nov 22 '22 at 10:06
  • There is no error. When I write the command without redirecting the output to a file, the exe works correctly and I see the result in the powershell console. The only issue is when I want to redirect the output, I got an empty file... – Herunòla Nov 23 '22 at 14:54
  • You are only redirecting Standard Output and not Error Output. See : https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_redirection?force_isolation=true&view=powershell-7.3#redirectable-output-streams – jdweng Nov 23 '22 at 15:39
  • anyway I found a workaround with another exe (which query server state). That confirm that the issue probably come from the exe itself and not from client environment (Windows and/or Powershell). Thanks anyway for your help ! – Herunòla Nov 24 '22 at 09:20

0 Answers0