Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Everything you need to know about PowerShell

1,306 views

Published on

Everything you need to know about powershell, get-help, get-command, get-member

Published in: Technology
  • Be the first to comment

Everything you need to know about PowerShell

  1. 1. Everything you need to learn PowerShell 2.0 Shane Hoey shane@powershelldownunder.com @shanehoey Sponsors
  2. 2. What We Will Talk About Overview of PowerShell Explore the Basics Start using PowerShell Today’s Agenda
  3. 3. Caveat #requires -version 2.0 I am not a Developer PowerShell Enthusiast not an expert.
  4. 4. Overview
  5. 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. 6. Windows PowerShell 2.0 Interactive shell Scripting language Object orientated Highly discoverable What is this thing ?
  7. 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. 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. 9. Windows PowerShell 2.0 Don’t Compare PowerShell to other scripting languages… And finally
  10. 10. PowerShell requires a new way of thinking!!!
  11. 11. Explore
  12. 12. 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
  13. 13. 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
  14. 14. 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
  15. 15. 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
  16. 16. 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
  17. 17. 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
  18. 18. 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
  19. 19. 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
  20. 20. 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
  21. 21. 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.
  22. 22. 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.
  23. 23. 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.
  24. 24. Windows PowerShell 2.0 Lets get all the red bricks $redblock=$block | where-object { ($_.colour –eq “red”) Its really just like playing with blocks.
  25. 25. 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.
  26. 26. 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…
  27. 27. 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
  28. 28. Best Practices Don’t develop in production. Use pseudo code. Test, test & test again . Script development
  29. 29. 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
  30. 30. Best Practices Always configure remoting via GPO where possible. Use Enable-PSRemoting rather than Set-WSManQuickConfig. Remoting
  31. 31. Start
  32. 32. 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
  33. 33. 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
  34. 34. 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
  35. 35. Related ContentPowershell Books Windows PowerShell Step by Step Windows PowerShell Unleashed Windows PowerShell 2.0 Best Practices Windows PowerShell 2.0 Administrators Pocket Consultant
  36. 36. Related ContentPowershell Software PowerGUI http://www.powergui.com PowerGUI Pro http://www.quest.com/powerguipro Sapien http://www.sapien.com
  37. 37. 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
  38. 38. 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

×