1

I wants to debug a power-shell script which is called from my Main power-shell script using PowerShell ISE. Below is the sample code of my Main script.

$myLog = "$scriptPath\BuildRelease\logs\LaLogs.log"

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
Set-Location -Path $scriptPath
Set-Location -Path BuildRelease
$paramList = "-ArgumentList -username $Login"

if($Mode -eq "False"){
    Start-Process powershell -ArgumentList '-noexit','-File', 'Release.ps1', $paramList
}

Here, I'm trying to step into Release.ps1 script using ISE.

I have tried to do this by pressing F11 key, but instead of debugger going to this script, script gets executed (same as Step Over, instead of Step into).

Does anyone know how can I do this??

Geeky Ninja
  • 6,002
  • 8
  • 41
  • 54
  • effin recursion... ;( – Jaqueline Vanek Aug 25 '16 at 08:15
  • kidding apart, whats teh logic behind "Start-Process powershell"? – Jaqueline Vanek Aug 25 '16 at 08:21
  • I'm executing the Release.ps1 script on another instance that's why I'm using Start-Process powershell. And this is something which customer wants me to do it like this way. – Geeky Ninja Aug 25 '16 at 08:32
  • 1
    Debug how? You can run it manually if you know the conditions that make it fail as Nico has suggested. If you want to test it in a live environment as-is you'll need to set up proper error trapping that logs errors to a file or displays them on a popup or something. If you know the error but need to see variables that's another story. We need to know what you're trying to do. – Deadly-Bagel Aug 25 '16 at 09:45

1 Answers1

0

by using Start-Process you run a new instance of powershell. So that why you can't debug your script. You can call other script in you script by using :

.\Release.ps1 -username $Login

And with this, you can debbug your script

Nico
  • 448
  • 4
  • 9
  • Is there any way to debug it with this way only (executing script in another instance)? – Geeky Ninja Aug 25 '16 at 08:33
  • I don't think so, you can try to use the parameter : `NoNewWindow` but don't think it work. Else if you must debug your script without ./, you can add manually breaking point to your second script by using : `New-PsBreakpoint` .... Some useful links : [PowerShell Debugger](https://technet.microsoft.com/en-us/library/ff730925.aspx) or [Quick and Efficient PowerShell Script Debugging](http://www.informit.com/articles/article.aspx?p=2421573). I never use this kind of debbug – Nico Aug 25 '16 at 14:00
  • Thanks Nico , that's really help me to debug it as per my requirement. – Geeky Ninja Aug 26 '16 at 10:48