Windows PowerShell - Billings .NET User Group - August 2009


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Shells have historically executed commands or utilities and presented results as textCmd.exe is the shell on windowsFew built-in commands, large variety of external utilities
  • You can filter by verb
  • You can filter by noun
  • Applications found in your path are available in PowerShellOutput from executables becomes a full-fledged object in PowerShell
  • Anything can be navigable using PowerShell providers!Even the registry!
  • SQLPS.exe, which comes with SQL Server 2008, is a custom PowerShell hostIt adds its own provider for navigating objects in SQL Server instances
  • The things returned by providers are itemsYou can use the –Item commands to work with them directlyIn this case when we get the subtext item we see that it is a Database type from the SMO library
  • Like everything else there are simple commands for filtering, looping, and sortingThose commands have simple aliasesFilter using whereSelect a new object from an existing object using selectLoop using foreach – notice that your have to ‘return’ something at the endTypical comparison operators like =, <, > aren’t used for parsing reasons
  • Creating a virtual machine using Hyper-V
  • Twitter!
  • It may be easier to believe now, but there is a lot you can do with PowerShell without even opening Visual Studio.
  • Windows PowerShell - Billings .NET User Group - August 2009

    1. 1. Windows PowerShell<br />John Clayton<br /><br />
    2. 2. Next generation command line shell<br />Processes objects instead of plain text<br />Large set of built-in commands<br />Consistent command parser<br />Scripting language<br />Designed for managing .NET objects<br />Provides a consistent environment for using cmdlets<br />Supports complex tasks without making simple tasks more complex<br />What is it?<br />
    3. 3. Built on .NET<br />Underlying objects are .NET<br />Extensible via cmdlets, providers, & host applications<br />Targeted at IT professionals<br />Supported by the latest server products<br />An astonishing amount can be accomplished without any programming<br />TechNet Script Center has hundreds of resources<br />What is it? (cont.)<br />
    4. 4. Using Windows PowerShell<br />Prepare to be amazed<br />
    5. 5. All commands use a Verb-Noun syntax<br />Self-describing, discoverable environment<br />Tab expansion<br />Command aliases<br />Brings in native applications & utilities<br />Object pipeline<br />Formatting<br />Navigation<br />Filtering<br />Scripting<br />The Shell<br />
    6. 6. Get-Command<br />
    7. 7. Get-Command<br />
    8. 8. Get-Command<br />
    9. 9. Get-Help<br />
    10. 10. Get-PSDrive<br />
    11. 11. Get-Member<br />
    12. 12. Command Aliases<br />
    13. 13. Native Applications<br />
    14. 14. Object pipeline<br />
    15. 15. Formatting<br />
    16. 16. Navigation<br />
    17. 17. Navigation<br />
    18. 18. Navigation<br />
    19. 19. Filtering, Looping, & Selecting<br />
    20. 20. Scripting<br />
    21. 21. Scripting<br />
    22. 22. Scripting<br />
    23. 23. Scripting<br />
    24. 24. Extending Windows PowerShell<br />If built in it is not, make it you shall<br />
    25. 25. Creating Cmdlets<br />In a class library reference System.Management.Automation<br />Hint: It’s not in the GAC!<br />
    26. 26. Creating Cmdlets<br />In a class library reference System.Configuration.Install<br />
    27. 27. Creating Cmdlets<br />Add a class and build your cmdlet<br />
    28. 28. Creating Cmdlets<br />Add a class and build your snap-in<br />
    29. 29. Creating Cmdlets<br />From an administrative Visual Studio command prompt navigate to your output directory and install your assembly<br />Gotcha: On a 64-bit system you’ll need to use the 64-bit version of InstallUtil.exe<br />
    30. 30. Creating Cmdlets<br />Launch a new instance of PowerShell<br />View the registered snap-ins:<br />Get-PSSnapIn –Registered<br />Register the snap-in:<br />Add-PSSnapIn<br />
    31. 31. Creating Cmdlets<br />Export the current console:<br />Export-Console<br />Include the exported file in your project<br />Set it to always copy to the output directory<br />
    32. 32. Creating Cmdlets<br />In the project properties set the debug action to start powershell.exe<br />In the command line arguments specify your console export file using the –PSConsoleFileflag<br />
    33. 33. Creating Cmdlets<br />
    34. 34. Hosting PowerShell<br />Create a new windows forms application<br />Add a reference to System.Management.Automation and your snap-in project<br />
    35. 35. Hosting PowerShell<br />In the form use a RunspaceConfiguration instance to add your snap-in, then create and open the runspace<br />
    36. 36. Hosting PowerShell<br />Using the runspace create and invoke a pipeline<br />Remember that Get-Proc is returning a collection and not individual items!<br />
    37. 37. PowerShell 1.0<br />Included in Windows Server 2008<br />Separate download for Windows XP SP2, Windows Server 2003, & Windows Vista<br />PowerShell 2.0<br />Included in Windows 7 & Windows Server 2008 R2<br />RC available for Windows XP SP3, Windows Server 2003 SP2, Vista SP1, & Windows Server 2008<br />Where do I get it?<br />
    38. 38.<br /><br /><br /><br /><br />Resources<br />