The Windows PowerShell ISE Interface.md - Juan-bit94/Ops401D10 GitHub Wiki

The Windows PowerShell ISE Interface

How to get started

  • To access the PowerShell ISE interface, click on the start button, type PowerShell ISE and then right click to run as administrator.
  • First thing you will see if the actual console. It has a flashing cursor, you can start typing in commands just from the command line.
  • On the right-hand side you will see the commands window. It shows you all the available commands and you can see by scrolling down that there are a lot of commands for the ISE. This is great because what you can do is you can group by modules, so if you click on the drop down menu at the top of the commands window, you will see that there are different modules.
  • You can for example click on the AppLocker module, and what that will do is show you all the various commands associated with the AppLocker module.
  • The commands window also has a name search box to look up commands, this is great because what you can do at this point is just click any of the commands and it will give you a little bit of help by way of explaining what this particular module does. You can even click the show more details button and it will inform you even more. It will even show you all the various parameters that you can use, some allow fill ins, and some of them are checked boxes.
    • For example: I searched the name copy in the commands window, I clicked on more detail and then I checked on force there to force this particular command.
  • For some commands that you look up in the commands window, there will be tab to let you Run the command, sometimes its grayed out, so instead we can choose to Insert, that will insert the command into the console.
  • That is the basic overview of the PowerShell ISE.

Running cmdlets in the ISE

  • This will explain how to run cmdlets in the PowerShell ISE.
    • Example:
      • I will open PowerShell ISE, on the commands window I will search for mkdir, I will click on get more detail in the commands window. I will look in the parameters for "mkdir", and on the path part, I will type what I want to call, my new directory or folder, and I'll just call it new. I then click insert and the code will be inserted into the PowerShell console. I press enter, and I get feedback here telling me that a new folder has been created, you can check on the File explore app.
      • Next I will try the remove-item command. I will go to the command window, search for it, and once I find it I will click on it. I will go ahead and show the details, it looks like it works in the opposite to mkdir. It will delete stuff, I will again enter the path (same path as the new directory I made). I will click insert and the entire command including the path is posted on the console.
  • Its pretty straight forward.

Introduction to Creating a Host Application

  • This will explain what PowerShell host applications are.
  • A PowerShell host application can specify and manage the runspace where commands are executed. It also allows you to execute commands by opening sessions on a local or remote computer. They are executed either synchronously or asynchronously.
  • The PowerShell class is used to host PowerShell applications, provisions methods that create a pipeline of processes, and commands are then executed in a runspace. A default runspace can be created that will assist with creating a host application, and a custom runspace can be created if a specific set of commands need to be executed.

Create a host application

  • AddCommand is used to add commands to the pipeline in three main steps.
    • Create PowerShell object
    • Add desired command to execute
    • Invoke chosen command
    • Example:
      • PowerShell ps = PowerShell.Create();
      • ps.AddCommand("Get-Activites");
      • ps.Invoke();
  • The first line uses the Create command to create the object. The second line uses the AddCommand to add the Get-Activities command. And the third line invokes the command.
  • AddParameter helps with adding parameters to a chosen command and AddStatement is used to add an additional statement to the end of the pipeline.
    • Example:
      • PowerShell AddStatement Method ()

Runspace

  • Operating environment for commands executed by the host application
  • This includes both data and any defined restrictions
  • Use InitialSessionState to create customized workspace.
  • Used to specify characteristics of the runspace
    • Commands
    • Modules
    • Variables
  • The customized workspace where every runspace has an associated Initial SessionState Object. It's used to specify characteristics of the runspace commands, modules and variables.