Запуск powershell script удаленно через ssh и получите код выхода

PSAppDeployToolkit uses pre-defined Exit Codes to indicate the success or failure of a deployment and can be used to control the flow of your deployment logic, or just to understand what happened during a deployment.

Exit CodeDescription
60000-68999Reserved for built-in exit codes in Deploy-Application.ps1, Deploy-Application.exe, and AppDeployToolkitMain.ps1.
69000 – 69999Recommended for user customized exit codes in Deploy-Application.ps1.
70000 – 79999Recommended for user customized exit codes in Deploy-Application.ps1.
60001An error occurred in Deploy-Application.ps1. Check your script syntax use.
60002Administrator privileges required for Execute-ProcessAsUser function.
60003Failure when loading .NET WinForms / WPF Assemblies.
60004Failure when displaying the Blocked Application dialog.
60005AllowSystemInteractionFallback option was not selected in the config XML file, so toolkit will not fall back to SYSTEM context with no interaction.
60006Failed to export the schedule task XML file in Execute-ProcessAsUser function.
60007Deploy-Application.ps1 failed to dot source AppDeployToolkitMain.ps1 either because it could not be found or there was an error while it was being dot sourced.
60008The -UserName parameter in the Execute-ProcessAsUser function has a default value that is empty because no logged in users were detected when the PSAppDeployToolkit was launched.
60009Deploy-Application.exe failed before PowerShell.exe process could be launched.
60013If Execute-Process function captures an exit code out of range for int32 then return this custom exit code.

Let me provide some background information, to complement your own answer:


Hossein Yousefi

ITNEXT

Such a surprise: if you run a cmd (.bat) script remotely, you will get the exit code, but in the case of your script being written in PowerShell (.ps1), you won’t get it.

:/>  Скачать активатор Windows 10 pro x64 x86 kms activator

Let’s make it clear

  • what’s our goal? to run a script or command remotely on a windows machine.
  • what’s the easiest way? install openssh-server on windows machine.
  • what’s the problem? if I run a powershell script remotely, it can’t get the exit code, better to say it always return 0 even when the script fails.
  • what’s the solution? There is No official solution for it.

What’s happening?

I usually run commands and scripts remotely on windows machine because I don’t want to get headache with WinRM or similar tools. how?

Firstly, you need to install openssh-server on windows machine.
One of the easiest way is:

Secondly, check if everything is OK, you are good to go. (from another VM)

Thirdly, It’s time to send your command through ssh.

It is possible to run encoded commands with powershell like:

This is a useful feature, how should we adopt it to use script instead of command??

In this way, you will get the right exit code.