none
Powershell Ctrl+c RRS feed

  • Question

  • Hello,

    I have a PS script that runs to gather info on remote servers, I'd like to be able to press  Ctrl+c   and have a prompt  "would you like to terminate (Y/N)?"  and of course if you press "Y" then it terminates back to the prompt and selecting "N" continues the task. 


    Can someone point me in the direction on how to accomplish this?  Thanks.

    Monday, August 25, 2014 9:33 PM

Answers

  • use Write-Debug for that..

    Click Suspend, it will get you into a prompt in the middle of the script for troubleshooting, you can see variable values, run commands, ...

    You will need these 2 commands on the top of your script or function to use -debug switch:

    [CmdletBinding()] 
    Param()

    For example:

    run the script or function with the -debug switch:

    notice the extra > at the prompt

    Run any debugging commands on this console, when done, type exit to go back


    Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable)



    Monday, August 25, 2014 9:36 PM

All replies

  • use Write-Debug for that..

    Click Suspend, it will get you into a prompt in the middle of the script for troubleshooting, you can see variable values, run commands, ...

    You will need these 2 commands on the top of your script or function to use -debug switch:

    [CmdletBinding()] 
    Param()

    For example:

    run the script or function with the -debug switch:

    notice the extra > at the prompt

    Run any debugging commands on this console, when done, type exit to go back


    Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable)



    Monday, August 25, 2014 9:36 PM
  • As Sam has pointed out, PowerShell has built-in support for debugging breakpoints.

    What's provoking the question?


    -- Bill Stewart [Bill_Stewart]

    Monday, August 25, 2014 9:54 PM
    Moderator