SlideShare ist ein Scribd-Unternehmen logo
1 von 112
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:sersdministrator> 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_Special.DeleteFolder(strFolder) Wscript.Echo “ to solve every day problems and run our computers well ”
“ 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_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
“ 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:oftwareicrosoft 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:indowsystem32riverstc>  dir   Directory: Microsoft.PowerShell.CoreileSystem::C:indowsystem32riverstc 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
“ 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:indowsystem32riverstc>  $x = dir PS C:indowsystem32riverstc>  $x   Directory: Microsoft.PowerShell.CoreileSystem::C:indowsystem32riverstc 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
PS C:indowsystem32riverstc>  $x[0]   Directory: Microsoft.PowerShell.CoreileSystem::C:indowsystem32riverstc Mode  LastWriteTime  Length Name ----  -------------  ------ ---- -a---  4/2/2007  3:51 AM  829 hosts
PS C:indowsystem32riverstc>  $x[0].Name hosts
PS C:indowsystem32riverstc>  dir | where { $_.Name -eq "hosts" }   Directory: Microsoft.PowerShell.CoreileSystem::C:indowsystem32riverstc Mode  LastWriteTime  Length Name ----  -------------  ------ ---- -a---  4/2/2007  3:51 AM  829 hosts
Get-ChildItem | Where-Object { $_.Name -eq "hosts" } Dir | Where { $_.Name -eq “hosts” } ls|?{ $_.Name -eq “hosts”}
PS C:indowsystem32riverstc>  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
PS C:indowsystem32riverstc>  dir | measure-object -property Length -Sum Count  : 5 Average  : Sum  : 23521 Maximum  : Minimum  : Property : Length
PS C:indowsystem32riverstc>  dir | foreach { $_.Length } | Measure-Object -Sum Count  : 5 Average  : Sum  : 23521 Maximum  : Minimum  : Property :
PS C:gt;  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:gt;  get-process | where { $_.WorkingSet -gt 150MB } | stop-process
PS C:gt;  get-process | where { $_.Name -eq 'firefox' } | format-list * __NounName  : Process Name  : firefox Handles  : 333 VM  : 207273984 WS  : 101548032 PM  : 84729856 NPM  : 18560 Path  : C:rogram Filesozilla Firefoxirefox.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 ...
PS C:gt;  function multBy2 { $_ * 2 } PS C:gt;  1..10 | foreach { multBy2 } 2 4 6 8 10 12 14 16 18 20
PS C:gt;  function concat($a, $b) { "$a-$b" } PS C:gt;  concat "hello" "there" hello-there PS C:gt;   concat -a "hello" -b "there" hello-there PS C:gt;  concat -b "hello" -a "there" there-hello
PS C:gt;  [System.Net.Dns]::GetHostByName("localhost") | fl HostName  : TARDIS Aliases  : {} AddressList : {127.0.0.1}
PS C:gt;  $rssUrl = "http://twitter.com/statuses/friends_timeline/766734.rss" PS C:gt;  $blog = [xml] (new-object system.net.webclient).DownloadString($rssUrl) PS C:gt;  $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! ;)
 
“ 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

Weitere Àhnliche Inhalte

Was ist angesagt?

PM : code faster
PM : code fasterPM : code faster
PM : code faster
PHPPRO
 
PowerShell-1
PowerShell-1PowerShell-1
PowerShell-1
Saravanan G
 
Final opensource record 2019
Final opensource record 2019Final opensource record 2019
Final opensource record 2019
Karthik Sekhar
 
Vagrant + Rouster at salesforce.com - PuppetConf 2013
Vagrant + Rouster at salesforce.com - PuppetConf 2013Vagrant + Rouster at salesforce.com - PuppetConf 2013
Vagrant + Rouster at salesforce.com - PuppetConf 2013
Puppet
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scripting
Tony Fabeen
 

Was ist angesagt? (20)

Introduction To Windows Power Shell
Introduction To Windows Power ShellIntroduction To Windows Power Shell
Introduction To Windows Power Shell
 
Pycon - Python for ethical hackers
Pycon - Python for ethical hackers Pycon - Python for ethical hackers
Pycon - Python for ethical hackers
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
 
Getting Started with PL/Proxy
Getting Started with PL/ProxyGetting Started with PL/Proxy
Getting Started with PL/Proxy
 
PM : code faster
PM : code fasterPM : code faster
PM : code faster
 
PowerShell-1
PowerShell-1PowerShell-1
PowerShell-1
 
Node.js API 서ëȄ 성늄 개선Ʞ
Node.js API 서ëȄ 성늄 개선ꞰNode.js API 서ëȄ 성늄 개선Ʞ
Node.js API 서ëȄ 성늄 개선Ʞ
 
Final opensource record 2019
Final opensource record 2019Final opensource record 2019
Final opensource record 2019
 
Mastering power shell - Windows
Mastering power shell - WindowsMastering power shell - Windows
Mastering power shell - Windows
 
Non-Relational Postgres / Bruce Momjian (EnterpriseDB)
Non-Relational Postgres / Bruce Momjian (EnterpriseDB)Non-Relational Postgres / Bruce Momjian (EnterpriseDB)
Non-Relational Postgres / Bruce Momjian (EnterpriseDB)
 
PostgreSQL and PL/Java
PostgreSQL and PL/JavaPostgreSQL and PL/Java
PostgreSQL and PL/Java
 
Psycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python ScriptPsycopg2 - Connect to PostgreSQL using Python Script
Psycopg2 - Connect to PostgreSQL using Python Script
 
Vagrant + Rouster at salesforce.com - PuppetConf 2013
Vagrant + Rouster at salesforce.com - PuppetConf 2013Vagrant + Rouster at salesforce.com - PuppetConf 2013
Vagrant + Rouster at salesforce.com - PuppetConf 2013
 
Flask restfulservices
Flask restfulservicesFlask restfulservices
Flask restfulservices
 
Devinsampa nginx-scripting
Devinsampa nginx-scriptingDevinsampa nginx-scripting
Devinsampa nginx-scripting
 
BUILDING MODERN PYTHON WEB FRAMEWORKS USING FLASK WITH NEIL GREY
BUILDING MODERN PYTHON WEB FRAMEWORKS USING FLASK WITH NEIL GREYBUILDING MODERN PYTHON WEB FRAMEWORKS USING FLASK WITH NEIL GREY
BUILDING MODERN PYTHON WEB FRAMEWORKS USING FLASK WITH NEIL GREY
 
"The little big project. From zero to hero in two weeks with 3 front-end engi...
"The little big project. From zero to hero in two weeks with 3 front-end engi..."The little big project. From zero to hero in two weeks with 3 front-end engi...
"The little big project. From zero to hero in two weeks with 3 front-end engi...
 
How to Design a Great API (using flask) [ploneconf2017]
How to Design a Great API (using flask) [ploneconf2017]How to Design a Great API (using flask) [ploneconf2017]
How to Design a Great API (using flask) [ploneconf2017]
 
Top Node.js Metrics to Watch
Top Node.js Metrics to WatchTop Node.js Metrics to Watch
Top Node.js Metrics to Watch
 
Resource-Oriented Web Services
Resource-Oriented Web ServicesResource-Oriented Web Services
Resource-Oriented Web Services
 

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

Ch23 system administration
Ch23 system administration Ch23 system administration
Ch23 system administration
Raja Waseem Akhtar
 
PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operations
grim_radical
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
Wesley Beary
 
Into The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and dockerInto The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and docker
Ortus Solutions, Corp
 
Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018
Ortus Solutions, Corp
 

Ähnlich wie Why and How Powershell will rule the Command Line - Barcamp LA 4 (20)

Get-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for EvilGet-Help: An intro to PowerShell and how to Use it for Evil
Get-Help: An intro to PowerShell and how to Use it for Evil
 
íŒŒìŽìŹ 개발환êČœ ê”Źì„±í•˜êž°ì˜ 끝판왕 - Docker Compose
íŒŒìŽìŹ 개발환êČœ ê”Źì„±í•˜êž°ì˜ 끝판왕 - Docker ComposeíŒŒìŽìŹ 개발환êČœ ê”Źì„±í•˜êž°ì˜ 끝판왕 - Docker Compose
íŒŒìŽìŹ 개발환êČœ ê”Źì„±í•˜êž°ì˜ 끝판왕 - Docker Compose
 
Ansible
AnsibleAnsible
Ansible
 
Null Bachaav - May 07 Attack Monitoring workshop.
Null Bachaav - May 07 Attack Monitoring workshop.Null Bachaav - May 07 Attack Monitoring workshop.
Null Bachaav - May 07 Attack Monitoring workshop.
 
Ch23 system administration
Ch23 system administration Ch23 system administration
Ch23 system administration
 
Unix And Shell Scripting
Unix And Shell ScriptingUnix And Shell Scripting
Unix And Shell Scripting
 
PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operations
 
2009 cluster user training
2009 cluster user training2009 cluster user training
2009 cluster user training
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
 
#WeSpeakLinux Session
#WeSpeakLinux Session#WeSpeakLinux Session
#WeSpeakLinux Session
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloud
 
Puppet Camp 2012
Puppet Camp 2012Puppet Camp 2012
Puppet Camp 2012
 
55 best linux tips, tricks and command lines
55 best linux tips, tricks and command lines55 best linux tips, tricks and command lines
55 best linux tips, tricks and command lines
 
PowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidPowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue Kid
 
Into The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and dockerInto The Box 2018 Going live with commandbox and docker
Into The Box 2018 Going live with commandbox and docker
 
Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018Going live with BommandBox and docker Into The Box 2018
Going live with BommandBox and docker Into The Box 2018
 
Revoke-Obfuscation
Revoke-ObfuscationRevoke-Obfuscation
Revoke-Obfuscation
 
Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014Postgres Vienna DB Meetup 2014
Postgres Vienna DB Meetup 2014
 
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 

KĂŒrzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

KĂŒrzlich hochgeladen (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

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

  • 1. Why and How PowerShell will rule the command line ilya haykinson / ilya@hulu.com
  • 7. # echo “ text is comfortable ”
  • 8. # echo “ the inputs are limited by the keys on the keyboard ”
  • 9. # echo “ there’s nothing to click ”
  • 10. $ echo “ text interfaces were around in our early computers ”
  • 11. [user@localhost ~]$ echo “ they’re still around now ”
  • 12. mysql> select ‘ we talk text to our databases ’
  • 13. (gdb) print “ and to debuggers ”
  • 14. A:> echo to systems that are old
  • 15. C:sersdministrator> echo even to systems that are new
  • 16. “ we use text to command our computers to do our bidding ”
  • 17. “ we’ve created little programs ”
  • 19. “ with funny names ”
  • 20. “ like ‘tar’ or ‘finger’ or ‘mount’ ”
  • 21. “ with cryptic names ”
  • 22. “ or ‘ps’ or ‘cacls’ or ‘fsck’ or ‘df’ ”
  • 23. “ we created ways for these programs ”
  • 24. cat to_talk | grep -e “.* to one another ” >> using_pipes
  • 25. # echo “ we added $variables ”
  • 26. # echo “ and `functions` ”
  • 27. # echo " and `(cat -s /tmp/ other ) && (echo ' concepts ')`"
  • 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. “ and then we did something strange and rather confusing ”
  • 30. “ we made all these programs ”
  • 31. “ talk text to one another ”
  • 32. “ this text is fine for us, humans ”
  • 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. “ but a computer has to parse ”
  • 35. “ so we build a command ”
  • 36. “ we give it a lot of intelligence ”
  • 37. “ we empower it to do one thing, and do it really, really well ”
  • 38. “ using brilliant data structures to store the data during processing ”
  • 39. “ it comes up with great output ”
  • 40. “ that ends up as text ”
  • 41. “ and then the next command ”
  • 42. “ in our pipeline ”
  • 43. “ has to understand that text ”
  • 44. “ figure out how to separate the ”
  • 45. /dev/ important / ext3 rw 0 0 /dev/md1 /usr/ from proc rw 0 0 #/dev/ the / not so much 0 0
  • 46. “ so that it can get this data ”
  • 47. “ back into brilliant data structures for processing ”
  • 48.  
  • 49. “ doing one thing well does not mean that we have to deal with text ”
  • 50. “ doing one thing well does not mean having your own command line parameter syntax ”
  • 51. ps -ef ps -aux ps aux
  • 52. ls -a ls --all wget -e wget --execute
  • 53. “ a command does not live on its own, even if it’s single-purposed ”
  • 54. “ it lives in a shell environment ”
  • 55. “ and interacts, indirectly, with other commands ”
  • 56. “ so enter PowerShell ”
  • 57. “ it’s a command shell for Windows operating systems ”
  • 58. “ and an evolved approach to how commands can interact ”
  • 59. “ it holds that each command ”
  • 60. “ should do only one thing ”
  • 61. “ and do it very well ”
  • 62. “ and that anyone should be able to write a new command ”
  • 63. “ and that commands are to be connected by pipes ”
  • 64. “ and that you need variables and control structures ”
  • 65. “ it’s really a fully-fledged programming language ”
  • 66. “ you talk to it using text ”
  • 67. “ but it talks to you using objects ”
  • 68. “ and talks to itself using objects ”
  • 69. “ you can see those objects ”
  • 70. “ or just see the text that represents them ”
  • 71.  
  • 72. “ in PowerShell, the command is called a ‘cmdlet’ ”
  • 74. “ commands have a common naming pattern ”
  • 76. Get-ChildItem Move-Item Sort-Object Set-Location Where-Object
  • 77. “ these commands can also have easier to remember aliases ”
  • 78. Get-ChildItem = dir, ls, gci Move-Item = move, mv, mi Sort-Object = sort Set-Location = cd, chdir, sl Where-Object = where, ?
  • 79. “ each command manipulates objects ”
  • 80. “ for example, ‘dir c: gets a listing of files in the root directory ”
  • 81. “ but you can also say ‘dir HKLM:oftwareicrosoft to iterate the registry ”
  • 82. “ because ‘dir’ just means ‘Get-ChildItem’ – get a list of children of an object that is a container ”
  • 83. “ the file system’s directories are considered containers ”
  • 84. “ as are registry keys ”
  • 85. PS C:indowsystem32riverstc> dir Directory: Microsoft.PowerShell.CoreileSystem::C:indowsystem32riverstc 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
  • 86. “ actually, the whole command line operates on objects ”
  • 87. “ if you do nothing else with them, they will be displayed as text ”
  • 88. “ if you pass them on, they will be processed as objects ”
  • 89. PS C:indowsystem32riverstc> $x = dir PS C:indowsystem32riverstc> $x Directory: Microsoft.PowerShell.CoreileSystem::C:indowsystem32riverstc 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
  • 90. PS C:indowsystem32riverstc> $x[0] Directory: Microsoft.PowerShell.CoreileSystem::C:indowsystem32riverstc Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 4/2/2007 3:51 AM 829 hosts
  • 91. PS C:indowsystem32riverstc> $x[0].Name hosts
  • 92. PS C:indowsystem32riverstc> dir | where { $_.Name -eq "hosts" } Directory: Microsoft.PowerShell.CoreileSystem::C:indowsystem32riverstc Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 4/2/2007 3:51 AM 829 hosts
  • 93. Get-ChildItem | Where-Object { $_.Name -eq "hosts" } Dir | Where { $_.Name -eq “hosts” } ls|?{ $_.Name -eq “hosts”}
  • 94. PS C:indowsystem32riverstc> 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
  • 95. PS C:indowsystem32riverstc> dir | measure-object -property Length -Sum Count : 5 Average : Sum : 23521 Maximum : Minimum : Property : Length
  • 96. PS C:indowsystem32riverstc> dir | foreach { $_.Length } | Measure-Object -Sum Count : 5 Average : Sum : 23521 Maximum : Minimum : Property :
  • 97. PS C:gt; 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:gt; get-process | where { $_.WorkingSet -gt 150MB } | stop-process
  • 98. PS C:gt; get-process | where { $_.Name -eq 'firefox' } | format-list * __NounName : Process Name : firefox Handles : 333 VM : 207273984 WS : 101548032 PM : 84729856 NPM : 18560 Path : C:rogram Filesozilla Firefoxirefox.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 ...
  • 99. PS C:gt; function multBy2 { $_ * 2 } PS C:gt; 1..10 | foreach { multBy2 } 2 4 6 8 10 12 14 16 18 20
  • 100. PS C:gt; function concat($a, $b) { "$a-$b" } PS C:gt; concat "hello" "there" hello-there PS C:gt; concat -a "hello" -b "there" hello-there PS C:gt; concat -b "hello" -a "there" there-hello
  • 101. PS C:gt; [System.Net.Dns]::GetHostByName("localhost") | fl HostName : TARDIS Aliases : {} AddressList : {127.0.0.1}
  • 102. PS C:gt; $rssUrl = "http://twitter.com/statuses/friends_timeline/766734.rss" PS C:gt; $blog = [xml] (new-object system.net.webclient).DownloadString($rssUrl) PS C:gt; $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! ;)
  • 103.  
  • 104. “ there is more to PowerShell ”
  • 105. “ you can write GUI apps in it, if you really want to ”
  • 106. “ you can administer servers ”
  • 107. “ you can completely replace your normal cmd.exe usage with it ”
  • 108. “ but even if you ignore it ”
  • 109. “ remember its lessons ”
  • 110. “ about the power of text ”
  • 111. “ and the power of objects ”