Powershell Debugging using PowerShell ISE

Background

Having a need to see why a Powershell code is not coming to the end I wanted.

Usual

Usually I will tinker with it by adding a bunch of Write-Host code, but today wanted to be a little lazy and also I can be more trusting as it is code I have already done enough with it already.

PowerShell ISE

Introduction

That is where Windows PowerShell Integrated Scripting Environment ( ISE ) comes in.

Install

If you are unable to run “Powershell ISE” through the start menu, please enable it.

Note, you need to be running at least MS Windows 7 or MS Windows 2008.

PowershellISE_launch_20180620_0552PM

Code

Powershell

Link

Import-Module ServerManager
Add-WindowsFeature PowerShell-ISE

GUI

Using Server Explorer
Link

  1. Open the Server Explorer
  2. Navigate to the Features Node
  3. Right-click on Features node, selectAdd Features
  4. You will get Add Features wizard with list of features provided with checkboxes.
  5. Check the “Windows PowerShell Integrated Scripting Environment (ISE)”
  6. Click on Next button
  7. Click on Install button.

Use

Start

Start Powershell ISE

Load Powershell File

Powershell_load_20180620_0556PM

Set Breakpoints

Review code and on each line that you want to break on, please press F9 or right click and select break-point from the drop-down menu.

powershellISE_Setbreakpoint_20180620_0558PM

 

Command Window

Watch Variable

Via Command Window, enter variable name and press enter command

watchVariable_20180620_0603PM

Set Variable

Program Argument

Via Command Window, set variable

Script

Sample

$PSDefaultParameterValues.add("Engine.ps1:CurrentLoginName","LAB\dadeniji")

Image

currentLoginName_20180620_0607PM.jpg

 

 

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s