Powershell_ 0 Basic Self-study course _3_ How to debug PS scripts with PowerShell Ise

Source: Internet
Author: User

Microsoft in the introduction of PS at the same time, did not forget its consistent style, what is to get an IDE environment, this does not forget to give PS also to an IDE environment,

With this IDE environment, you can create a PSL file that you can debug with the PSL file.

1. IDE Interface

Let's look at the interface of the IDE environment:

: The IDE environment is divided into three panes, and the layout of the pane can be customized. The pane in the upper-left corner is the output pane, and the results are executed in the IDE

The bottom left window is the interactive pane, also called the command pane, where you can enter the command you want to execute, and this pane will also prompt the current working path.

The working path is: C:\users\vol_20120330, this path is the home directory of the current user of my Computer (home directory); the right pane is used to create

PSL file, I typed a simple command: Get-command, this pane also becomes the Script pane.

2. Toggle different pane Styles

Through the View menu can switch different panes layout style, also can switch through the toolbar, specifically do not switch, you can open the PS ise to try it yourself.

3. Debugging function

After editing the script code, you can run it to see the results, which can be done through the commands on the Debug menu. As shown in the following:

As can be seen, PS ise support breakpoint debugging function, this makes up for the previous script debugging not easy disadvantage, in cmd execution script

, a special method is needed to get general debugging information, and this function is enhanced in PS.

4. Run the script

There are three main ways to run scripts in the IDE environment: Debug menu, Shortcut F5, toolbar Run button, button for Microsoft other IDE environment

The shape is a green triangle; the run result of the executed script file:

Of course, you can also execute the script in the command pane, but this is inconvenient and requires a script execution path.

5. Adjust the font

The default fonts in several panes are small and look uncomfortable, and the IDE environment provides the ability to zoom in and out of fonts, and to set the font size by menu and shortcut keys.

The shortcut keys are:

Ctrl-+ Increase Font

Ctrl--Decrease font

6. Debugging function

Debugging is done primarily through breakpoints, and debugging information is provided.

1) View debug information

When the command runs incorrectly, the ISE provides the same error message as the PS console. Such as

For example: The red font in the Output pane is an error message, which clearly indicates the type of error and the location of the error. The exact meaning of the error message is clear.

There is no explanation here.

2) Insert/delete breakpoint

Ise supports breakpoint debugging, you can insert and delete breakpoints;.

People familiar with Microsoft's other IDE environments are familiar with breakpoints represented by a circle, where the ISE makes a big improvement when inserting a breakpoint, with a highlighted color at the breakpoint

To indicate that it is convenient for people to view breakpoints, unlike circle breakpoints, where breakpoints are more difficult to distinguish.

3) Breakpoint Debug output

After inserting a breakpoint, click to run or execute the F5 command, you can debug it;

Executes to the breakpoint, the script stops running, and the color at the breakpoint of the script window changes, so that at many breakpoints, it is clear that running to that

Position, the command pane has changed, as shown above, the title bar of the command pane appears [DBG]:, is currently in debug mode, and the output prompt becomes

The ">>>" form, and the output pane also prompts you where to debug the breakpoint.

4) Commissioning

To demonstrate the debugging process, I added a command to the script and started debug mode, such as:

As you can see, the script runs to the breakpoint and stops, so we can get some information in the current session by entering a command in the command pane, or

Gets the value of the script variable object, as shown in:

Enter the above command, then enter to get the following output:

  

  

Through this debugger, you can easily debug your own scripts, can greatly accelerate the efficiency and accuracy of script development, but also can deepen the understanding of PS operation;

Complex debugging technology here is no longer said, interested friends can try their own.

Today, the Discovery Garden Blog features a functional improvement: auto-save; feel this good, can be convenient to write at once, and then continue to write, so

You don't have to be late to finish it.

Powershell_ 0 Basic Self-study course _3_ How to debug PS scripts with PowerShell Ise

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.