Differences

This shows you the differences between the selected revisions of the page.

2020-09-16 2020-10-20
grammar (martin) Debugging PowerShell Scripts (martin)
Line 68: Line 68:
  echo WinSCP done   echo WinSCP done
) > C:\script\example.out 2>&1 ) > C:\script\example.out 2>&1
 +</code>
 +
 +===== [[powershell]] Debugging PowerShell Scripts =====
 +While the previously mentioned techniques are mostly focused on WinSCP scripting and batch files, some can be used even when debugging a PowerShell script ([[library_powershell|that uses WinSCP .NET assembly]]).
 +
 +Particularly, when debugging problems starting the PowerShell script itself, it is useful to wrap the ''powershell.exe''/''pwsh.exe'' command to a batch file. That will allow you to redirect a PowerShell output to a file, the [[#output|same way as shown above for ''winscp.com'']].
 +
 +If you know that your PowerShell is starting, but fails somewhere before WinSCP session log ([[library_session#sessionlogpath|''Session.SessionLogPath'']]) is created, and you do not want to create the batch file wrapper, use [[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript|''Start-Transcript'' cmdlet]] in the PowerShell script itself. Using it, you can capture all the PowerShell output that you would otherwise see on the PowerShell console. Put the following line to the beginning of your script (but after the ''param'' statement, if you have one):
 +
 +<code powershell>
 +Start-Transcript C:\script\example.transcript
</code> </code>

Last modified: by martin