5. Windows PowerShell 2.0
MS-DOS - .bat
Windows 95 - Cmd
Windows 98 - Windows Scripting Host
Windows 2000 – WSH Logon scripts
3rd Party Solutions – Autoit, KiXtart, WinBatch etc
June 2003 Monad 1st Public Beta
November 2006 Windows Powershell v1.0 (rtw)
August 2009 Windows PowerShell v2.0
How did we get here ?
7. Windows PowerShell 2.0
Automate everything
Consistent
Sharable and reusable
Admin-Focused, Learn once, use often !
Scalable
Common engineering criteria
Why Should we use it ?
8. Windows PowerShell 2.0
<#Start Rant>
PowerShell is designed to be secure by default. Understand
script execution, and script signing before you change the
policy. Execution Policy determines how scripts execute
only.
Do not confuse Execution Policies with security!
<#End Rant>
Secure by Design and Secure by Default
13. Windows PowerShell 2.0
Cmdlet (pronounced “command-let”) are single feature
commands that manipulate objects. They can be executed
from the console or a script, and generally named verb-noun.
Windows 7 with no modules loaded has 236 cmdlets.
The 3 Cmdlets you must learn are Get-Help, Get-Command,
Get-Member.
CMDLET
15. Windows PowerShell 2.0
Always focus on the objects, every action you perform takes
place in the context of objects.
Objects are a structured collections of data that includes
the objects type, properties, and methods.
Objects
16. Windows PowerShell 2.0
Most objects have Properties, A property is the data that is
associated with an object, and it describes the object.
Objects of the same type have the same properties however
their values will differ.
To display a property value we can use the dot method
Properties
17. Windows PowerShell 2.0
Methods are a set of instructions that specify an action you can
do to that object. Most objects include at least one method.
To invoke a method specify the method name after the object,
include the arguments in parentheses, If no arguments still
include parentheses.
Methods
18. Windows PowerShell 2.0
A pipeline is a series of commands that are separated by the
pipeline operator |
Commands are processed left to right and processed as a single
operation.
Each pipeline sends the result of the preceding command to the
input of the next.
Once the pipeline is finished the results are generally displayed.
Pipelines
19. Everything you need to know…
Get-Help is your new best friend.
Retrieves help information about PowerShell.
4 main types of help available…
–full
–details
–examples
-online
Get-Help
20. Everything you need to know…
To list all available commands in you current PowerShell session
we use the Get-Command cmdlet.
Information comes directly from the actual commands.
Get-Command works with Cmdlets, Scripts, Alias, Functions,
Native applications.
Get-Command
21. Everything you need to know…
Everything PowerShell returns is an object, we use Get-
Member to obtain the properties and methods of that object.
This is one of the most important cmdlets you will learn .
Get-Member
22.
23. Windows PowerShell 2.0
Lists available modules including “block” module
Get-Module –Listavailable
Imports the “block” module into current session
Import-Module –Name block
Its really just like playing with blocks.
24. Windows PowerShell 2.0
Lists all the available commands from the “block” module
Get-Command –Module block
Displays help on get-block cmdlet
Get-Help Get-block
Its really just like playing with blocks.
25. Windows PowerShell 2.0
Now lets look at what we can do
$Blocks = Get-Block *
Lets work out what the object is
$Blocks | Get-Member
Material – property
Colour – property
stack – method
Its really just like playing with blocks.
26. Windows PowerShell 2.0
Lets get all the red bricks
$redblock=$block | where-object { ($_.colour –eq “red”)
Its really just like playing with blocks.
27. PowerShell = Childs Play
Get the red block with the letter A
$a=$block | where-object { ($_.colour –eq “red”) –and ($_.letter –eq “A”)
Select the first blue block with the letter L
$b=$block | ?{($_.colour –eq “blue”)–and($_.letter–eq “L”) | select –first 1
Use a cmdlet join $a to $b
Stack-Block –block $b –ontopblock $a
Using .Net method to join $a to $b
($b).stack($a)
Its really just like playing with blocks.
28.
29. Best Practices
Focus on the object.
Don’t use aliases in scripts.
Always use full parameter names.
Use cmdlets whenever possible .Net should be the exception.
or what I wish I knew when I started learning
Powershell…
30. Best Practices
Always use #Requires –version x.x.
Focus on doing one thing and do it well.
Focus on code reuse.
Don’t try to format objects within your script/function.
Use standard naming conventions (verb-noun).
Document your scripts and include help !
Avoid hard coding.
Designing Scripts
32. Best Practices
Always sign scripts.
Always set execution policy to Allsigned.
Never set execution policy to unrestricted or remote signed.
Always run scripts with least privilege.
Running Scripts in Production environments
33. Best Practices
Always configure remoting via GPO where possible.
Use Enable-PSRemoting rather than Set-WSManQuickConfig.
Remoting
35. Related Content
Join a PowerShell Usergroup
Website http://powershelldownunder.com
Join our mailing list
Lunchtime and Evening Usergroup Meetings
Email info@powershelldownunder.com
Twitter @psdownunder
Facebook PowerShellDownUnder
LinkedIn Australian PowerShell Usergroup
or in other words a Shameless Plug
36. Related ContentCommunity Resourses
Forums, blogs, etc – Great Resources
powershellcommunity.org
powershell.com
Script Repository – Save you time
poshcode.org
Podcasts – Add it to Zune
powerscripting.wordpress.com
or in other words more shameless plugs
37. Related ContentHey Scripting Guys
http://scriptingguys.com
@scriptingguys
Hey Scripting Guy Blog – 99% PowerShell for last 18 months
Hey Scripting Guy is 7 days a week!
Script Repository – Over 4,000 scripts
Official Scripting Guys Forum – sweet!
TechNet Library content – good stuff
38. Related ContentPowershell Books
Windows PowerShell Step by Step
Windows PowerShell Unleashed
Windows PowerShell 2.0 Best Practices
Windows PowerShell 2.0 Administrators Pocket Consultant
40. Question and
Answer
Question and Answer Time
Presentation and Related Content will be Posted to http://bit.ly/powershell/
Everything you need to know about Windows PowerShell 2.0
41. Thanks For Listening!
Be sure to submit your feedback
if you want to be in the draw to
win the Xbox 360 and other prizes!
Sponsors