Introduction To Power Shell

2,087 views
1,984 views

Published on

This is a presentation for my "Introduction to PowerShell" workshop

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,087
On SlideShare
0
From Embeds
0
Number of Embeds
159
Actions
Shares
0
Downloads
77
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Introduction To Power Shell

  1. 1. Introduction to PowerShell<br />Ivan Suhinin<br />Senior Software Engineer<br />
  2. 2. What is PowerShell?<br />Automation engine<br />Shell environment<br />Scripting language<br />
  3. 3. PowerShell as a shell<br />A full replacement for CMD<br />At last something bash-like in Windows<br />Just… feel the power!<br />
  4. 4. PowerShell as a language<br />Variables: $a, $name<br />Arrays: $arr = 1,2,3,4,5,6; $sarr=1..6<br />Hashes: $h = @{“Key1" = 23; “Key2" = 894}<br />Functions: function hi ($name) { echo "Hi, $name!" }<br />Classes:($o = New-Object Object) |Add-Member NoteProperty Name “Bianco"<br />
  5. 5. PowerShell as an automation tool<br />Predefined set of commands with lots of extensions<br />Easy batch operations<br />Simple command interconnections (pipelining)<br />
  6. 6. Command types<br />Cmdlets – Get-Location<br />Functions<br />User scripts - *.ps1<br />Native applications (msbuild, csc)<br />
  7. 7. Cmdlets<br />Predefined set of commands<br />Form: Verb-Noun:<br />Get-Location<br />Get-ChildItem<br />Set-Location<br />Long, descriptive names for scripts<br />Aliases for daily usage<br />
  8. 8. Aliases<br />Creating short names for long cmdlets<br />Get-Alias, Set-Alias<br />Makes scripting more friendly<br />By default has standard UNIX aliases<br />ls, ps, pwd, date, kill, gal, pushd, popd<br />
  9. 9. Wiring commands up<br />Pipelining: Get-Location | Get-Member<br />Functional style<br />.NET objects instead of strings (bash)<br />Output becomes input<br />Select – selecting only needed information<br />Where – filtering results<br />Group – grouping results<br />ForEach – processing each input value<br />
  10. 10. PowerShell providers<br />Adapters to different subsystems<br />Get-PSProvider, Get-PSDrive<br />Default: WSMan, Alias, Environment, FileSystem, Registry<br />Extended: IIS, SQL, SharePoint, VMWare<br />
  11. 11. Using external components<br />Windows Management Instrumentation (WMI)<br />gwmi win32_service<br />gwmi win32_operatingsystem<br />COM<br />(New-Object -ComObjectWScript.Shell).Run("calc.exe")<br />
  12. 12. Using .NET<br />Importing assemblies:[Reflection.Assembly]::LoadWithPartialName("System.Messaging")<br />Calling static methods:[System.Messaging.MessageQueue]::GetPrivateQueuesByMachine("localhost")<br />Creating and using objects:$b = New-Object System.Text.StringBuilder$b.Append("Hello!")<br />
  13. 13. man<br />Ultimate help system<br />Examples<br />Detailed<br />Full<br />
  14. 14. Demo: deleting MSMQ queues<br />
  15. 15. Demo: sorting SQL tables by size<br />
  16. 16. Demo: real-life deployment script<br />
  17. 17. Development environment<br />Autocompletion<br />Tab key<br />Wildcards<br />Works for methods<br />PowerShell ISE<br />PowerGUI<br />
  18. 18. Q & A<br />

×