0

I usually add temporary code to show running variables
and when the script is ready I have to delete this code.

Is there any way of terminate a script (.ps1)
(quit / exit / break / ... ) called from the console command line...
and leave the script variables in memory
so we can inspect them in the console...

I do not want to use PSBreakpoint in this...
I just want to exit to console...
and type the name of the variable
to display the content

Thx!

ZEE
  • 2,931
  • 5
  • 35
  • 47
  • 1
    You should read the help [about_Scopes](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes?view=powershell-5.1) and maybe about [Write-Verbose](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-verbose?view=powershell-5.1) and [Write-Debug](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-debug?view=powershell-5.1). With this in your script and with `CmdletBinding`you can run your script with the parameter `-Debug` or `-Verbose` and it'll show what you prepared/need. – Olaf Apr 28 '19 at 02:11
  • 2
    Leaving in the middle whether this is the correct way of debugging (I often do this myself instead of using the debug capabilities of an IDE), you might break out your script using [`Break Script`](https://stackoverflow.com/a/45030002/1701026) and if you [Dot Source](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scripts?view=powershell-6#script-scope-and-dot-sourcing) your script, it will load the variables in the current scope. – iRon Apr 28 '19 at 07:51

0 Answers0