Why and How PowerShell will rule the command line ilya haykinson / ilya@hulu.com
/Text
/Text/Provides
/Text/Provides/Context
/Text/Provides/Structure
/Text/Provides/Uniformity
# echo “ text is comfortable ”
# echo “ the inputs are limited by the keys on the keyboard ”
# echo “ there’s nothing to click ”
$ echo “ text interfaces were around in our early computers ”
[user@localhost ~]$ echo “ they’re still around now ”
mysql> select ‘ we talk text to our databases ’
(gdb) print “ and to debuggers ”
A:> echo  to systems that are old
C:UsersAdministrator> echo  even to systems that are new
“ we use text to command our computers to do our bidding ”
“ we’ve created little programs ”
“ commands ”
“ with funny names ”
“ like ‘tar’ or ‘finger’ or ‘mount’ ”
“ with cryptic names ”
“ or ‘ps’ or ‘cacls’ or ‘fsck’ or ‘df’ ”
“ we created ways for these programs ”
cat  to_talk  | grep -e “.* to one another ” >>  using_pipes
# echo “ we added $variables ”
# echo “ and `functions` ”
# echo " and  `(cat -s /tmp/ other  ) && (echo '  concepts ')`"
Set  or_Special  = Wscript.CreateObject("Scripting.FileSystemObject") strFolder = “ programming languages ”  or_...
“ and then we did something strange and rather confusing ”
“ we made all these programs ”
“ talk text to one another ”
“ this text is fine for us, humans ”
22:39:55 up 21 days, 18:39,  4 users,  load average: 0.05, 0.14, 0.15 USER  TTY  FROM  LOGIN@  IDLE  JCPU  PCPU WHAT we_kn...
“ but a computer has to parse ”
“ so we build a command ”
“ we give it a lot of intelligence ”
“ we empower it to do one thing, and do it really, really well ”
“ using brilliant data structures to store the data during processing ”
“ it comes up with great output ”
“ that ends up as text ”
“ and then the next command ”
“ in our pipeline ”
“ has to understand that text ”
“ figure out how to separate the ”
/dev/ important  / ext3 rw 0 0 /dev/md1 /usr/ from  proc rw 0 0 #/dev/ the  / not so much  0 0
“ so that it can get this data ”
“ back into brilliant data structures for processing ”
 
“ doing one thing well does not mean that we have to deal with text ”
“ doing one thing well does not mean having your own command line parameter syntax ”
ps -ef ps -aux ps aux
ls -a ls --all wget -e wget --execute
“ a command does not live on its own, even if it’s single-purposed ”
“ it lives in a shell environment ”
“ and interacts, indirectly, with other commands ”
“ so enter PowerShell ”
“ it’s a command shell for Windows operating systems ”
“ and an evolved approach to how commands can interact ”
“ it holds that each command ”
“ should do only one thing ”
“ and do it very well ”
“ and that anyone should be able to write a new command ”
“ and that commands are to be connected by pipes ”
“ and that you need variables and control structures ”
“ it’s really a fully-fledged programming language ”
“ you talk to it using text ”
“ but it talks to you using objects ”
“ and talks to itself using objects ”
“ you can see those objects ”
“ or just see the text that represents them ”
 
“ in PowerShell, the command is called a ‘cmdlet’ ”
“ pronounced ‘commandlet’ ”
“ commands have a common naming pattern ”
“ ’ verb-noun’ ”
Get-ChildItem Move-Item Sort-Object Set-Location Where-Object
“ these commands can also have easier to remember aliases ”
Get-ChildItem = dir, ls, gci Move-Item = move, mv, mi Sort-Object = sort Set-Location = cd, chdir, sl Where-Object = where...
“ each command manipulates objects ”
“ for example, ‘dir c:’ gets a listing of files in the root directory ”
“ but you can also say ‘dir HKLM:SoftwareMicrosoft’ to iterate the registry ”
“ because ‘dir’ just means ‘Get-ChildItem’ – get a list of children of an object that is a container ”
“ the file system’s directories are considered containers ”
“ as are registry keys ”
PS C:WindowsSystem32driversetc>  dir   Directory: Microsoft.PowerShell.CoreFileSystem::C:WindowsSystem32driversetc Mode  L...
“ actually, the whole command line operates on objects ”
“ if you do nothing else with them, they will be displayed as text ”
“ if you pass them on, they will be processed as objects ”
PS C:WindowsSystem32driversetc>  $x = dir PS C:WindowsSystem32driversetc>  $x   Directory: Microsoft.PowerShell.CoreFileSy...
PS C:WindowsSystem32driversetc>  $x[0]   Directory: Microsoft.PowerShell.CoreFileSystem::C:WindowsSystem32driversetc Mode ...
PS C:WindowsSystem32driversetc>  $x[0].Name hosts
PS C:WindowsSystem32driversetc>  dir | where { $_.Name -eq "hosts" }   Directory: Microsoft.PowerShell.CoreFileS...
Get-ChildItem | Where-Object { $_.Name -eq "hosts" } Dir | Where { $_.Name -eq “hosts” } ls|?{ $_.Name -eq “host...
PS C:WindowsSystem32driversetc>  dir | foreach { "The file $($_.Name) is $($_.Length) bytes long" } The file hos...
PS C:WindowsSystem32driversetc>  dir | measure-object -property Length -Sum Count  : 5 Average  : Sum  : 23521 Maximum  : ...
PS C:WindowsSystem32driversetc>  dir | foreach { $_.Length } | Measure-Object -Sum Count  : 5 Average  : Sum  : 23521 Maxi...
PS C:>  get-process | where { $_.WorkingSet -gt 150MB } Handles  NPM(K)  PM(K)  WS(K) VM(M)  CPU(s)  Id ProcessName ------...
PS C:>  get-process | where { $_.Name -eq 'firefox' } | format-list * __NounName  : Process Name  : firefox Handles  : 333...
PS C:>  function multBy2 { $_ * 2 } PS C:>  1..10 | foreach { multBy2 } 2 4 6 8 10 12 14 16 18 20
PS C:>  function concat($a, $b) { "$a-$b" } PS C:>  concat "hello" "there" hello-there PS C:...
PS C:>  [System.Net.Dns]::GetHostByName("localhost") | fl HostName  : TARDIS Aliases  : {} AddressList : {127.0....
PS C:>  $rssUrl = "http://twitter.com/statuses/friends_timeline/766734.rss" PS C:>  $blog = [xml] (new-object sy...
 
“ there is more to PowerShell ”
“ you can write GUI apps in it, if you really want to ”
“ you can administer servers ”
“ you can completely replace your normal cmd.exe usage with it ”
“ but even if you ignore it ”
“ remember its lessons ”
“ about the power of text ”
“ and the power of objects ”
thank you
Upcoming SlideShare
Loading in …5
×

Why and How Powershell will rule the Command Line - Barcamp LA 4

4,418 views

Published on

Presentation by Ilya Haykinson

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,418
On SlideShare
0
From Embeds
0
Number of Embeds
54
Actions
Shares
0
Downloads
140
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide
  • Why and How Powershell will rule the Command Line - Barcamp LA 4

    1. 1. Why and How PowerShell will rule the command line ilya haykinson / ilya@hulu.com
    2. 2. /Text
    3. 3. /Text/Provides
    4. 4. /Text/Provides/Context
    5. 5. /Text/Provides/Structure
    6. 6. /Text/Provides/Uniformity
    7. 7. # echo “ text is comfortable ”
    8. 8. # echo “ the inputs are limited by the keys on the keyboard ”
    9. 9. # echo “ there’s nothing to click ”
    10. 10. $ echo “ text interfaces were around in our early computers ”
    11. 11. [user@localhost ~]$ echo “ they’re still around now ”
    12. 12. mysql> select ‘ we talk text to our databases ’
    13. 13. (gdb) print “ and to debuggers ”
    14. 14. A:> echo to systems that are old
    15. 15. C:UsersAdministrator> echo even to systems that are new
    16. 16. “ we use text to command our computers to do our bidding ”
    17. 17. “ we’ve created little programs ”
    18. 18. “ commands ”
    19. 19. “ with funny names ”
    20. 20. “ like ‘tar’ or ‘finger’ or ‘mount’ ”
    21. 21. “ with cryptic names ”
    22. 22. “ or ‘ps’ or ‘cacls’ or ‘fsck’ or ‘df’ ”
    23. 23. “ we created ways for these programs ”
    24. 24. cat to_talk | grep -e “.* to one another ” >> using_pipes
    25. 25. # echo “ we added $variables ”
    26. 26. # echo “ and `functions` ”
    27. 27. # echo " and `(cat -s /tmp/ other ) && (echo ' concepts ')`"
    28. 28. Set or_Special = Wscript.CreateObject("Scripting.FileSystemObject") strFolder = “ programming languages ” or_Special.DeleteFolder(strFolder) Wscript.Echo “ to solve every day problems and run our computers well ”
    29. 29. “ and then we did something strange and rather confusing ”
    30. 30. “ we made all these programs ”
    31. 31. “ talk text to one another ”
    32. 32. “ this text is fine for us, humans ”
    33. 33. 22:39:55 up 21 days, 18:39, 4 users, load average: 0.05, 0.14, 0.15 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT we_know pts/0 pool-72-71-240-1 00:58 21:41m 4.39s 4.35s pine user123 pts/2 lgb-static-66.18 Fri17 29:11m 0.01s 0.01s -bash how_to pts/3 understand 33-22l 21:38 0.00s 0.29s 0.03s sshd: howto [priv] what_we pts/4 lgb-static-66.18 Fri12 29:22m 0.04s 0.04s see
    34. 34. “ but a computer has to parse ”
    35. 35. “ so we build a command ”
    36. 36. “ we give it a lot of intelligence ”
    37. 37. “ we empower it to do one thing, and do it really, really well ”
    38. 38. “ using brilliant data structures to store the data during processing ”
    39. 39. “ it comes up with great output ”
    40. 40. “ that ends up as text ”
    41. 41. “ and then the next command ”
    42. 42. “ in our pipeline ”
    43. 43. “ has to understand that text ”
    44. 44. “ figure out how to separate the ”
    45. 45. /dev/ important / ext3 rw 0 0 /dev/md1 /usr/ from proc rw 0 0 #/dev/ the / not so much 0 0
    46. 46. “ so that it can get this data ”
    47. 47. “ back into brilliant data structures for processing ”
    48. 49. “ doing one thing well does not mean that we have to deal with text ”
    49. 50. “ doing one thing well does not mean having your own command line parameter syntax ”
    50. 51. ps -ef ps -aux ps aux
    51. 52. ls -a ls --all wget -e wget --execute
    52. 53. “ a command does not live on its own, even if it’s single-purposed ”
    53. 54. “ it lives in a shell environment ”
    54. 55. “ and interacts, indirectly, with other commands ”
    55. 56. “ so enter PowerShell ”
    56. 57. “ it’s a command shell for Windows operating systems ”
    57. 58. “ and an evolved approach to how commands can interact ”
    58. 59. “ it holds that each command ”
    59. 60. “ should do only one thing ”
    60. 61. “ and do it very well ”
    61. 62. “ and that anyone should be able to write a new command ”
    62. 63. “ and that commands are to be connected by pipes ”
    63. 64. “ and that you need variables and control structures ”
    64. 65. “ it’s really a fully-fledged programming language ”
    65. 66. “ you talk to it using text ”
    66. 67. “ but it talks to you using objects ”
    67. 68. “ and talks to itself using objects ”
    68. 69. “ you can see those objects ”
    69. 70. “ or just see the text that represents them ”
    70. 72. “ in PowerShell, the command is called a ‘cmdlet’ ”
    71. 73. “ pronounced ‘commandlet’ ”
    72. 74. “ commands have a common naming pattern ”
    73. 75. “ ’ verb-noun’ ”
    74. 76. Get-ChildItem Move-Item Sort-Object Set-Location Where-Object
    75. 77. “ these commands can also have easier to remember aliases ”
    76. 78. Get-ChildItem = dir, ls, gci Move-Item = move, mv, mi Sort-Object = sort Set-Location = cd, chdir, sl Where-Object = where, ?
    77. 79. “ each command manipulates objects ”
    78. 80. “ for example, ‘dir c:’ gets a listing of files in the root directory ”
    79. 81. “ but you can also say ‘dir HKLM:SoftwareMicrosoft’ to iterate the registry ”
    80. 82. “ because ‘dir’ just means ‘Get-ChildItem’ – get a list of children of an object that is a container ”
    81. 83. “ the file system’s directories are considered containers ”
    82. 84. “ as are registry keys ”
    83. 85. PS C:WindowsSystem32driversetc> dir Directory: Microsoft.PowerShell.CoreFileSystem::C:WindowsSystem32driversetc Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 4/2/2007 3:51 AM 829 hosts -a--- 9/18/2006 2:41 PM 3683 lmhosts.sam -a--- 9/18/2006 2:41 PM 407 networks -a--- 9/18/2006 2:41 PM 1358 protocol -a--- 9/18/2006 2:41 PM 17244 services
    84. 86. “ actually, the whole command line operates on objects ”
    85. 87. “ if you do nothing else with them, they will be displayed as text ”
    86. 88. “ if you pass them on, they will be processed as objects ”
    87. 89. PS C:WindowsSystem32driversetc> $x = dir PS C:WindowsSystem32driversetc> $x Directory: Microsoft.PowerShell.CoreFileSystem::C:WindowsSystem32driversetc Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 4/2/2007 3:51 AM 829 hosts -a--- 9/18/2006 2:41 PM 3683 lmhosts.sam -a--- 9/18/2006 2:41 PM 407 networks -a--- 9/18/2006 2:41 PM 1358 protocol -a--- 9/18/2006 2:41 PM 17244 services
    88. 90. PS C:WindowsSystem32driversetc> $x[0] Directory: Microsoft.PowerShell.CoreFileSystem::C:WindowsSystem32driversetc Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 4/2/2007 3:51 AM 829 hosts
    89. 91. PS C:WindowsSystem32driversetc> $x[0].Name hosts
    90. 92. PS C:WindowsSystem32driversetc> dir | where { $_.Name -eq "hosts" } Directory: Microsoft.PowerShell.CoreFileSystem::C:WindowsSystem32driversetc Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 4/2/2007 3:51 AM 829 hosts
    91. 93. Get-ChildItem | Where-Object { $_.Name -eq "hosts" } Dir | Where { $_.Name -eq “hosts” } ls|?{ $_.Name -eq “hosts”}
    92. 94. PS C:WindowsSystem32driversetc> dir | foreach { "The file $($_.Name) is $($_.Length) bytes long" } The file hosts is 829 bytes long The file lmhosts.sam is 3683 bytes long The file networks is 407 bytes long The file protocol is 1358 bytes long The file services is 17244 bytes long
    93. 95. PS C:WindowsSystem32driversetc> dir | measure-object -property Length -Sum Count : 5 Average : Sum : 23521 Maximum : Minimum : Property : Length
    94. 96. PS C:WindowsSystem32driversetc> dir | foreach { $_.Length } | Measure-Object -Sum Count : 5 Average : Sum : 23521 Maximum : Minimum : Property :
    95. 97. PS C:> get-process | where { $_.WorkingSet -gt 150MB } Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 658 19 175704 155676 470 506.77 36964 firefox PS C:> get-process | where { $_.WorkingSet -gt 150MB } | stop-process
    96. 98. PS C:> get-process | where { $_.Name -eq 'firefox' } | format-list * __NounName : Process Name : firefox Handles : 333 VM : 207273984 WS : 101548032 PM : 84729856 NPM : 18560 Path : C:Program FilesMozilla Firefoxfirefox.exe Company : Mozilla Corporation CPU : 11.9028763 FileVersion : 1.8.1.9: 2007102514 ProductVersion : 2.0.0.9 Description : Firefox Product : Firefox Id : 6052 PriorityClass : Normal HandleCount : 333 WorkingSet : 101548032 PagedMemorySize : 84729856 ...
    97. 99. PS C:> function multBy2 { $_ * 2 } PS C:> 1..10 | foreach { multBy2 } 2 4 6 8 10 12 14 16 18 20
    98. 100. PS C:> function concat($a, $b) { "$a-$b" } PS C:> concat "hello" "there" hello-there PS C:> concat -a "hello" -b "there" hello-there PS C:> concat -b "hello" -a "there" there-hello
    99. 101. PS C:> [System.Net.Dns]::GetHostByName("localhost") | fl HostName : TARDIS Aliases : {} AddressList : {127.0.0.1}
    100. 102. PS C:> $rssUrl = "http://twitter.com/statuses/friends_timeline/766734.rss" PS C:> $blog = [xml] (new-object system.net.webclient).DownloadString($rssUrl) PS C:> $blog.rss.channel.item | select title -first 8 title ----- ori: @ori thinks there's a lot of drunk-twittering going on at barcampla. Yeah I just referred to myself in the thir... Zadi: Going to curl up and watch Eraserhead, finally. 'Night guys. Remember to turn back the clock. annieisms: i can haz crochet mouse? http://tinyurl.com/3ylmj7 ccg: hey BarCampers (and others) remember to set your clocks (and by clocks, I mean phones) back an hour tonight, Ya... Mickipedia: Everyone follow @egredman for some great music! Mickipedia: ...and party every day! heathervescent: Omg theses french djs blown mah mind. groby: @barcampla Clearly, you guys don't know what's good! Salty Black Licorice FTW! ;)
    101. 104. “ there is more to PowerShell ”
    102. 105. “ you can write GUI apps in it, if you really want to ”
    103. 106. “ you can administer servers ”
    104. 107. “ you can completely replace your normal cmd.exe usage with it ”
    105. 108. “ but even if you ignore it ”
    106. 109. “ remember its lessons ”
    107. 110. “ about the power of text ”
    108. 111. “ and the power of objects ”
    109. 112. thank you

    ×