PowerShell ISE

The PowerShell ISE was introduced with PowerShell v3. Unfortunately, it has not evolved too much from past versions, which is why it is losing its importance and is now finally going to be replaced by Visual Studio Code. Though replacing might be the wrong verb in this context—the PowerShell ISE will continue to stick to the Windows PowerShell version on Windows systems. VSCode, in comparison, is free and easily downloadable on every device. The problem is that the PowerShell ISE is still being used by the largest number of people—even today. This is why I am still explaining it very briefly, but then will move on to VSCode and prioritize VSCode in the whole book. You will recognize by yourself that VSCode is the more powerful and flexible tool; it is also continuously getting new features.  

PowerShell ISE can be executed through PowerShell_ISE.exe, which is located in the C:WindowsSystem32WindowsPowerShellv1.0 folder. The user interface is very simple and looks like this:

As you can see in the preceding screenshot, you have the dark blue console pane and the white script pane. In the script pane, you can prepare scripts before executing them either in parts or as a full script. For this you also have hotkeys available, which you should get to know and use them in a frequent manner:

  • F5 for the execution of the whole script
  • F8 to only run the selection
A complete overview of all hotkeys can be found in Appendix A, PowerShell ISE Hotkeys

You should get to know most of these; this will help you to create faster scripts and work more efficiently with the tools.

In addition, you can also use the ISE for debugging. With the F9 hotkey, you can set breakpoints in the script pane. A breakpoint forces the debugger to stop at the specified line, where you can then take a dedicated look at the variables and step through the whole script line by line. To accomplish this, you have three actions available after hitting a break point:

For most coding languages and tools, these three options are available:

  • F10 just executes the whole line and continues to the next line. If there is a function used in this line, this function is just stepped over, which is why this is named Step Over.
  • F11 executes every line of code in its minimal pieces. This means that by the functions that are used are being opened and each single line of code is being stepped through. This is why it is called Step Into.
  • The last one is Shift + F11, which jumps out of the current function block. The next line shown is the initial executing line of the function. This hotkey can be used in combination with F11 to jump into and then Shift + F11 to jump back out of functions. This is why it is called Step Out.

This is the basic knowledge about debugging that we will use throughout the whole book. It is important that you get used to the possibilities in debugging and use them frequently. Coming with PowerShell, there are many skills you need to evolve. People with a developer background will already have many helpful skills. But if you are not familiar with these techniques because you come, for example, from an administration background, it is highly recommended that you learn these developer skills. They will come in very handy if you need to do some troubleshooting, and you will also learn how to write better code.

Another great feature for beginners in the ISE is the so-called Command Window. You can open it up by either executing the Show-Command cmdlet or pressing the dedicated icon:

It will show you a complete command list, where you can now easily filter the modules and the cmdlets by name. By marking a dedicated cmdlet, its information, the cmdlet parameters and the common parameters are visualized:

This can be a good tool to get familiar with the available cmdlets and their execution. Try to fill in the parameters and use them. Mandatory parameters, for example, for the Remove-ServiceEndpoint cmdlet, are marked with an asterisk.

Another great feature from the PowerShell ISE are the so-called snippets. You can open the snippet list by pressing Ctrl + J:

It brings up a list of available snippets, which can be used to speed up the creation of your script or even just to prevent any manual errors. You can also use them as a learning resource to see how specific tasks can be coded. If you, for example, are not aware of how to code a do...until loop, the snippets will provide you with some initial guidance. For the moment, let's leave it there. Coding techniques and working with snippets will be explained in detail with VSCode later. 

The official Microsoft documentation are evolving continuously and are a great learning resource. If you are not familiar with the PowerShell ISE or just want to increase or check your current knowledge, you should take a look at their content: https://docs.microsoft.com/en-us/powershell/scripting/core-powershell/ise/introducing-the-windows-powershell-ise.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.143.239