# PowerShell/ISE

This lesson introduces PowerShell ISE, the integrated scripting environment by examining the scripting environment, automatic code completion, and by creating simple scripts.

## Objectives and Skills

After completing this lesson, you will be able to:
* Modify execution policy settings to allow locally written scripts to run.
* Understand cmdlet aliases.
* Explain the difference between Write-Host and Write-Output.
* Use Write-Output to display messages to the user.
* Stop and start services using a PowerShell script.

## Readings

* Wikipedia: Integrated development environment
* Wikipedia: Intelligent code completion
* Microsoft TechNet: Using the Windows PowerShell ISE
* BonusBits: Mastering PowerShell Chapter 2 - Interactive PowerShell

## Multimedia

* YouTube: Microsoft Windows 8 First Look: Windows PowerShell
* Microsoft Virtual Academy: Advanced Tools & Scripting with PowerShell 3.0

## Examples
#### Get-Alias

The Get-Alias cmdlet displays a list of current Windows PowerShell aliases.

#### Get-ExecutionPolicy

The Get-ExecutionPolicy cmdlet returns the current Windows PowerShell execution policy security level.

#### Set-ExecutionPolicy

The Set-ExecutionPolicy cmdlet sets the Windows PowerShell execution policy security level.

#### Start-Service

The Start-Service cmdlet starts a stopped service or services. Starting services on Windows requires running PowerShell or the corresponding script as an administrator.

#### Stop-Service

The Stop-Service cmdlet stops a running service or services. Stopping services on Windows requires running PowerShell or the corresponding script as an administrator.

#### Write-Host

The Write-Host cmdlet writes directly to the host environment, bypassing the pipeline.

#### Write-Output

The Write-Output cmdlet writes to the pipeline.

#### Comparing Write-Host and Write-Output

When there are no other commands in the pipeline, Write-Host and Write-Output appear functionally identical. The difference is clear, however, when the pipeline is used. To provide the most functionality for future use and automation of PowerShell scripts, Write-Output is the preferred output cmdlet. The Get-Date cmdlet may be used to demonstrate the difference between Write-Host and Write-Output.

## Activities

* Review Microsoft TechNet: Using the Set-ExecutionPolicy Cmdlet. Change your local execution policy to RemoteSigned so that you can run your own local saved scripts.
* Review Microsoft TechNet: Using the Get-Alias Cmdlet. Display a list of all Windows PowerShell aliases.
* Review Microsoft TechNet: Using the Write-Host Cmdlet, Microsoft TechNet: Write-Output, and Microsoft TechNet: Using the Get-Date Cmdlet. Experiment with the different commands and the pipeline to ensure you understand the difference between Write-Host and Write-Output.
* Review Microsoft TechNet: Write-Output. Create a script that uses Write-Output to display your name. Try something like 'Hello Wikiversity!'. Add a comment at the top of the script that describes the purpose of the script. Then save the script as a file and experiment with running the script file using both PowerShell and PowerShell ISE.
* Review Microsoft TechNet: Using the Stop-Service Cmdlet and Microsoft TechNet: Using the Start-Service Cmdlet. Use Get-Service to get a list of running services. Then write a script that will stop and restart the Print Spooler service. Add a comment at the top of the script that describes the purpose of the script. Save the script as a file and experiment with running the script file using both PowerShell and PowerShell ISE.

## Lesson Summary

* An integrated development environment (IDE) or interactive development environment is a software application that provides comprehensive facilities to computer programmers for software development.
* An IDE normally consists of a source code editor, build automation tools and a debugger.
* Most modern IDEs offer Intelligent code completion features.
* Automatic code completion in PowerShell and PowerShell ISE is accomplished using the <Tab> key.
* Cmdlet parameters are automatically listed by entering the dash or hyphen (-) character and then using the <Tab> key to cycle through the list.
* New PowerShell tabs are created using the File menu.
* Remote PowerShell tabs may be created to establish a session on a remote computer.
* The PowerShell ISE console executes commands when you press <Enter>.
* Multiple commands may be executed together in the PowerShell ISE console in sequence by separating them using <Shift>+<Enter>.
* To stop a command in PowerShell ISE, on the toolbar, click Stop Operation, or press <Ctrl>+<Break>.
* The default Windows PowerShell execution policy setting is Restricted.
* PowerShell ISE script breakpoints can be set using Toggle Breakpoint or by pressing the <F9> key.
* PowerShell profiles may be established by configuring a PowerShell script to run automatically when you start a new PowerShell or PowerShell ISE session.
* Saved PowerShell scripts are run using a full or relative path. The relative path for a PowerShell script in the current directory would be .\script.ps1.
* The Get-Alias cmdlet displays a list of current Windows PowerShell aliases.
* The Get-ExecutionPolicy cmdlet returns the current Windows PowerShell execution policy security level.
* The Set-ExecutionPolicy cmdlet sets the Windows PowerShell execution policy security level.
* The Start-Service cmdlet starts a stopped service or services.
* The Stop-Service cmdlet stops a running service or services.
* Starting and stopping services on Windows requires running PowerShell or the corresponding script as an administrator.
* The Write-Host cmdlet writes directly to the host environment, bypassing the pipeline.
* The Write-Output cmdlet writes to the pipeline.

## Key Terms
### breakpoint

    An intentional stopping or pausing place in a program, put in place for debugging purposes.

### debugging

    A methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware, thus making it behave as expected.

## Assessments

* Flashcards: Quizlet: Windows PowerShell - ISE
* Quiz: Quizlet: Windows PowerShell - ISE

## See Also

* Microsoft TechNet Virtual Lab: Windows Server 2012 R2 - Windows PowerShell Fundamentals
* PowerGUI: Free PowerShell IDE