How to troubleshoot deploy-application.ps1 coding issues

Background:
I am new to PSADT and learning it because my employer is using it. I am used to troubleshooting PowerShell wrappers, for SCCM applications, in PowerShell ISE where I can see the errors and iterate to perfection before deploying in SCCM.

Question:
When I run “deploy-application.exe install” at a command line and something isn’t right inside deploy-application.ps1, how do I get real time feedback and a line number about the error like PowerShell ISE gave me before I started using PSADT? PowerShell ISE tells me instantly with red text what the problem is when not using PSADT. But PSADT has custom PowerShell that is not understood inside PowerShell ISE. Is there a logging flag that can be enabled deploy-application.ps1?

1 Like

You can open powershell_ise in the context matching your package execution context :

  • As a simple user
  • As an administrator
  • As LocalSytem (using Sysinternals PSEXEC.EXE -i -s powershell_ise)

Then open your deploy-application.ps1, put any breakpoints you want inside and run it.

If your package has some specific parameters in the command line (i.e in my company we are passing some extra parameters like : deploy-application.exe -inv -defertimes 5) you can modify them in the deploy-application.ps1 Param() block. In this block, also modify your DeploymentType / DeploymentMode to match the context you wanna debug.

Before getting into this, i test my package locally on a test machine, just starting deploy-application.exe in one of the above contexts (user/admin/localsystem interractive or not interractive) and check :
1- The exitcode
2- The generated logfile

If the package execution is very fast and you get no logs, then you have a syntax error somewhere and starting deploy-application.ps1 in powershell_ise will show you where it is.

If you have a package log, most of the time you have everything you need in it.

1 Like

I like to use Visual Studio Code to make my changes to PSADT. It allows me to set step through points, as well as automating a number of simple syntax things. You can run your ps1 right from within it too. It’s a free download.

Try to run ISE elevated on your TEST PC.

edit deploy-application.PS1 in ISE

In the blue “console” in ISE enter: deploy-application.PS1 install
If that doesn’t work, add the full path to deploy-application.PS1

If you like ISE, get ISE Steroids (~U$50)

I hate ISE, so I still use PowerGUI.