SlideShare una empresa de Scribd logo
1 de 41
Everything you
need to learn
PowerShell 2.0
Shane Hoey
shane@powershelldownunder.com
@shanehoey
Sponsors
What We Will Talk About
Overview of PowerShell
Explore the Basics
Start using PowerShell
Today’s Agenda
Caveat
#requires -version 2.0
I am not a Developer
PowerShell Enthusiast not an expert.
Overview
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 ?
Windows PowerShell 2.0
Interactive shell
Scripting language
Object orientated
Highly discoverable
What is this thing ?
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 ?
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
Windows PowerShell 2.0
Don’t Compare PowerShell to other scripting languages…
And finally
PowerShell requires a new way of thinking!!!
Explore
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
Common Cmdlets
 Add-Computer
 Checkpoint-
Computer
 Clear-Eventlog
 Compare-Object
 Foreach-Object
 Get-Command
 Get-Credential
 Get-date
 Get-Eventlog
 Get-Help
 Get-hotfix
 Get-Location
 Get-Member
 Get-Process
 Get-Random
 Get-service
 Group-Object
 New-Object
 Remove-Computer
 Restart-computer
 SelectObject
 Set-Location
 Sort-Object
 Stop-computer
 Stop-service
 Write-Eventlog
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
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
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
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
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
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
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
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.
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.
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.
Windows PowerShell 2.0
Lets get all the red bricks
$redblock=$block | where-object { ($_.colour –eq “red”)
Its really just like playing with blocks.
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.
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…
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
Best Practices
Don’t develop in production.
Use pseudo code.
Test, test & test again .
Script development
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
Best Practices
Always configure remoting via GPO where possible.
Use Enable-PSRemoting rather than Set-WSManQuickConfig.
Remoting
Start
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
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
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
Related ContentPowershell Books
Windows PowerShell Step by Step
Windows PowerShell Unleashed
Windows PowerShell 2.0 Best Practices
Windows PowerShell 2.0 Administrators Pocket Consultant
Related ContentPowershell Software
PowerGUI http://www.powergui.com
PowerGUI Pro http://www.quest.com/powerguipro
Sapien http://www.sapien.com
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
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

Más contenido relacionado

La actualidad más candente

Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
Ankur Dongre
 
Developing components and extensions for ext js
Developing components and extensions for ext jsDeveloping components and extensions for ext js
Developing components and extensions for ext js
Mats Bryntse
 
New Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian BergmannNew Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian Bergmann
dpc
 

La actualidad más candente (20)

Introduction to Protractor
Introduction to ProtractorIntroduction to Protractor
Introduction to Protractor
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
 
Sunil phani's take on windows powershell
Sunil phani's take on windows powershellSunil phani's take on windows powershell
Sunil phani's take on windows powershell
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Ext Js
Ext JsExt Js
Ext Js
 
PHPUnit
PHPUnitPHPUnit
PHPUnit
 
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
파이썬 플라스크로 배우는 웹프로그래밍 #2 (ABCD)
 
Repo Madness: Taming the Open-Source Repository
Repo Madness: Taming the Open-Source RepositoryRepo Madness: Taming the Open-Source Repository
Repo Madness: Taming the Open-Source Repository
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
Phpunit testing
Phpunit testingPhpunit testing
Phpunit testing
 
Advanced PHPUnit Testing
Advanced PHPUnit TestingAdvanced PHPUnit Testing
Advanced PHPUnit Testing
 
Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015Why Your Test Suite Sucks - PHPCon PL 2015
Why Your Test Suite Sucks - PHPCon PL 2015
 
What you can do In WatiR
What you can do In WatiRWhat you can do In WatiR
What you can do In WatiR
 
Developing components and extensions for ext js
Developing components and extensions for ext jsDeveloping components and extensions for ext js
Developing components and extensions for ext js
 
watir-webdriver
watir-webdriverwatir-webdriver
watir-webdriver
 
New Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian BergmannNew Features PHPUnit 3.3 - Sebastian Bergmann
New Features PHPUnit 3.3 - Sebastian Bergmann
 
Unit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitUnit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnit
 
Laravel Unit Testing
Laravel Unit TestingLaravel Unit Testing
Laravel Unit Testing
 

Destacado

PowerShell Scripting and Modularization (TechMentor Fall 2011)
PowerShell Scripting and Modularization (TechMentor Fall 2011)PowerShell Scripting and Modularization (TechMentor Fall 2011)
PowerShell Scripting and Modularization (TechMentor Fall 2011)
Concentrated Technology
 
PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)
Concentrated Technology
 

Destacado (11)

Wsv315 Windows Power Shell For Beginners
Wsv315 Windows Power Shell For BeginnersWsv315 Windows Power Shell For Beginners
Wsv315 Windows Power Shell For Beginners
 
Wsv406 Advanced Automation Using Windows Power Shell2.0
Wsv406 Advanced Automation Using Windows Power Shell2.0Wsv406 Advanced Automation Using Windows Power Shell2.0
Wsv406 Advanced Automation Using Windows Power Shell2.0
 
Windows 2012 R2 Multi Server Management
Windows 2012 R2 Multi Server ManagementWindows 2012 R2 Multi Server Management
Windows 2012 R2 Multi Server Management
 
VMUG - Mastering PowerShell to Call RESTful API Endpoints
VMUG - Mastering PowerShell to Call RESTful API EndpointsVMUG - Mastering PowerShell to Call RESTful API Endpoints
VMUG - Mastering PowerShell to Call RESTful API Endpoints
 
Introduction To Windows Power Shell
Introduction To Windows Power ShellIntroduction To Windows Power Shell
Introduction To Windows Power Shell
 
PowerShell Scripting and Modularization (TechMentor Fall 2011)
PowerShell Scripting and Modularization (TechMentor Fall 2011)PowerShell Scripting and Modularization (TechMentor Fall 2011)
PowerShell Scripting and Modularization (TechMentor Fall 2011)
 
10 PowerShell Mistakes, Trips and Traps
10 PowerShell Mistakes, Trips and Traps10 PowerShell Mistakes, Trips and Traps
10 PowerShell Mistakes, Trips and Traps
 
PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)PowerShell Core Skills (TechMentor Fall 2011)
PowerShell Core Skills (TechMentor Fall 2011)
 
Building an Empire with PowerShell
Building an Empire with PowerShellBuilding an Empire with PowerShell
Building an Empire with PowerShell
 
Introduction To Power Shell
Introduction To Power ShellIntroduction To Power Shell
Introduction To Power Shell
 
An Introduction to Windows PowerShell
An Introduction to Windows PowerShellAn Introduction to Windows PowerShell
An Introduction to Windows PowerShell
 

Similar a Everything you need to know about PowerShell

Brian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with PowershellBrian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
SharePoint Saturday NY
 
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with PowershellBrian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
SharePoint Saturday NY
 
Inventory your network and clients with PowerShell
Inventory your network and clients with PowerShellInventory your network and clients with PowerShell
Inventory your network and clients with PowerShell
Concentrated Technology
 
Automating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShellAutomating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShell
Concentrated Technology
 

Similar a Everything you need to know about PowerShell (20)

PowerShell Workshop Series: Session 2
PowerShell Workshop Series: Session 2PowerShell Workshop Series: Session 2
PowerShell Workshop Series: Session 2
 
Power shell training
Power shell trainingPower shell training
Power shell training
 
PowerShell for SharePoint Developers
PowerShell for SharePoint DevelopersPowerShell for SharePoint Developers
PowerShell for SharePoint Developers
 
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with PowershellBrian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
 
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with PowershellBrian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
 
Inventory your network and clients with PowerShell
Inventory your network and clients with PowerShellInventory your network and clients with PowerShell
Inventory your network and clients with PowerShell
 
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdfLearn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
 
PowerShell for Penetration Testers
PowerShell for Penetration TestersPowerShell for Penetration Testers
PowerShell for Penetration Testers
 
PowerShell crash course
PowerShell crash coursePowerShell crash course
PowerShell crash course
 
Holy PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood editionHoly PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood edition
 
Modern Python Testing
Modern Python TestingModern Python Testing
Modern Python Testing
 
PowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidPowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue Kid
 
Windows PowerShell
Windows PowerShellWindows PowerShell
Windows PowerShell
 
Basic commands for powershell : Configuring Windows PowerShell and working wi...
Basic commands for powershell : Configuring Windows PowerShell and working wi...Basic commands for powershell : Configuring Windows PowerShell and working wi...
Basic commands for powershell : Configuring Windows PowerShell and working wi...
 
Powershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge ClubPowershell Seminar @ ITWorx CuttingEdge Club
Powershell Seminar @ ITWorx CuttingEdge Club
 
Automating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShellAutomating Active Directory mgmt in PowerShell
Automating Active Directory mgmt in PowerShell
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
 
Sql Server & PowerShell
Sql Server & PowerShellSql Server & PowerShell
Sql Server & PowerShell
 
No-script PowerShell v2
No-script PowerShell v2No-script PowerShell v2
No-script PowerShell v2
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 

Everything you need to know about PowerShell

  • 1. Everything you need to learn PowerShell 2.0 Shane Hoey shane@powershelldownunder.com @shanehoey Sponsors
  • 2. What We Will Talk About Overview of PowerShell Explore the Basics Start using PowerShell Today’s Agenda
  • 3. Caveat #requires -version 2.0 I am not a Developer PowerShell Enthusiast not an expert.
  • 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 ?
  • 6. Windows PowerShell 2.0 Interactive shell Scripting language Object orientated Highly discoverable What is this thing ?
  • 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
  • 9. Windows PowerShell 2.0 Don’t Compare PowerShell to other scripting languages… And finally
  • 10.
  • 11. PowerShell requires a new way of thinking!!!
  • 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
  • 14. Common Cmdlets  Add-Computer  Checkpoint- Computer  Clear-Eventlog  Compare-Object  Foreach-Object  Get-Command  Get-Credential  Get-date  Get-Eventlog  Get-Help  Get-hotfix  Get-Location  Get-Member  Get-Process  Get-Random  Get-service  Group-Object  New-Object  Remove-Computer  Restart-computer  SelectObject  Set-Location  Sort-Object  Stop-computer  Stop-service  Write-Eventlog
  • 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
  • 31. Best Practices Don’t develop in production. Use pseudo code. Test, test & test again . Script development
  • 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
  • 34. Start
  • 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
  • 39. Related ContentPowershell Software PowerGUI http://www.powergui.com PowerGUI Pro http://www.quest.com/powerguipro Sapien http://www.sapien.com
  • 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