Monday, January 13, 2014

Microsoft Virtual Academy: PowerShell M07 (Part 3)

Here we are module 7 only two more.  This is a short segment but lots of information.  To keep things short I have split it among three posts.  Check the Overview to see what is covered under this post.

To start your own learning check out Microsoft Virtual Academy:
(http://www.microsoftvirtualacademy.com/training-courses/getting-started-with-powershell-3-0-jump-start?o=3276#?fbid=aVs9FfAH2DJ)
(rewritten based on my notes available here: https://drive.google.com/file/d/0B1fwreWrAZioQ28xTmx0d29HUzQ/edit?usp=sharing)

Module 7: "Getting prepared for automation" consists of 2 video segments totaling ≈ 26 minutes along with a PowerPoint of 12 slides.

Overview
Output to Screen

 PowerShell offers a few ways to provide output to the screen from your script.   The most common is Write-Host as it provides the ability to format colors.  There are some issues with using Write-Host as it breaks the ability to pipe.  To maintain the pipeline use Write-Output.  To provide you color text they have provided us with Write-Error / Write-Warning / Write-Debug.

Write-Host
    Allows output to the screen to be formatted.  Remember this breaks pipeline usage and is not best practice in a script.

Write-Host "Hello" -Foregroundcolor red -BackGroundColor green
         Sets colors
   
     Outputs:Hello
   

Write-Output
   Way to output to screen with out breaking pipeline.

Write-Output "Hello"

    Outputs: Hello

Write-Error / Write-Warning / Write-Debug
    All three of these cmdlets use the default PowerShell scheme to maintain quick recognition.

Write-Warning "Help, Help"

    Outputs: Help, Help

Write-Error "Doom, Doom"

     Outputs: Doom, Doom

Check out the rest of this segment:
Part 1: http://cleeit.blogspot.com/2014/01/MVA-powershell-m07-part1.html
Part 2: http://cleeit.blogspot.com/2014/01/MVA-powershell-m07-part2.html

No comments:

Post a Comment