PowerShell crash course

19
75-Minute PowerShell Crash Course Don Jones Concentrated Technology http:// ConcentratedTech.com

description

 

Transcript of PowerShell crash course

Page 1: PowerShell crash course

75-Minute PowerShellCrash Course

Don Jones

Concentrated Technology

http://ConcentratedTech.com

Page 2: PowerShell crash course

This slide deck was used in one of our many conference presentations. We hope you enjoy it, and invite you to use it

within your own organization however you like.

For more information on our company, including information on private classes and upcoming conference appearances, please

visit our Web site, www.ConcentratedTech.com.

For links to newly-posted decks, follow us on Twitter:@concentrateddon or @concentratdgreg

This work is copyright ©Concentrated Technology, LLC

Page 3: PowerShell crash course

Welcome!

• This is a demo-intensive session• I will capture a shell transcript, which will be

downloadable from ConcentratedTech.com next week

• We will be covering key PowerShell usage patterns, using real-world tasks as our examples

• Learn these patterns and you can teach yourself to do anything you need to in PowerShell!

Page 4: PowerShell crash course

Loading Extensions, Learning Commands

• Snap-ins● Get-PSSnapin –registered● Add-PSSnapin name● Get-Command –pssnapin name

• Modules● Get-Module –listAvailable● Import-Module name● Get-Command –module name

• Help

Page 5: PowerShell crash course

Cmdlet and Parameter Names

• Verb-Noun (singular)• -parameter value• “quotes” or ‘quotes’ around strings

(especially those with spaces)• Use wildcards with Help• Use –full, -example, and –online with Help• Use Get-Command

Page 6: PowerShell crash course

Piping

• Like Dir | More only better• Pipeline binding ByValue• Pipeline binding ByPropertyName

Page 7: PowerShell crash course

Tables of Information

• Use Get-Member to see all “columns”• Okay, these are really objects

● Column = Property● Row = Object (instance)

• Use Format-List, Format-Wide, and Format-Table

• Wildcards work with –property param

Page 8: PowerShell crash course

Manipulating Objects

• Sorting• Measuring• Selecting subsets• Selecting specific properties (columns)

Page 9: PowerShell crash course

Custom Property Syntax

• Works with –property parameter of Select-Object, Format-List, and Format-Table

• @{n=’col_name’;e={$_.expression}}

• Use this to bind ComputerName ByPropertyname

Page 10: PowerShell crash course

Two More Ways of GettingComputer Names

• (parentheses) with Select-Object –expand• (parentheses) with Get-Content

Page 11: PowerShell crash course

Comparison Operators

• -eq, -ne• -ge, -gt• -le, -lt• -list (use * as wildcard)

• All case-sensitive• Use –ceq, -cne, etc. for case-sensitive

Page 12: PowerShell crash course

Filtering Objects

• Use Where-Object –filterscript {}• $_ represents the current row (object) that

was piped in

Page 13: PowerShell crash course

WMI

• Use Get-WmiObject• Specify –class and –namespace (unless

it’s root\CIMv2)• Specify –filter (WQL syntax, not

PowerShell)• Pipe to Sort, Select, Where, etc.• Drive inventory anyone?• Use WMI Explorer to locate stuff

Page 14: PowerShell crash course

Making Things Happen

• Batch Cmdlets• Invoke-WmiMethod• ForEach-Object ($_ again!)

Page 15: PowerShell crash course

Scripting

• Security (Get/Set-ExecutionPolicy)• .PS1 filename extension• Parameterizing a script• Script Function• Dot-sourcing functions• Creating “script modules”

Page 16: PowerShell crash course

That was a lot.

• There’s a ton more…• Learn it all in an hour a day with Learn

Windows PowerShell in a Month of Lunches● Companion DVD includes 99 demo videos

that align with each chapter

Page 17: PowerShell crash course

Final Q&A

• Text DONJ to 50500 for contact info

• See me for add’l resources

● Books● Workshop recordings● Demo videos● Etc

• Slide decks posted to ConcentratedTech.com by next week

Page 18: PowerShell crash course

Your Feedback is Important

Please fill out a session evaluation form drop it off at the conference registration

desk.

Thank you!

Page 19: PowerShell crash course

This slide deck was used in one of our many conference presentations. We hope you enjoy it, and invite you to use it

within your own organization however you like.

For more information on our company, including information on private classes and upcoming conference appearances, please

visit our Web site, www.ConcentratedTech.com.

For links to newly-posted decks, follow us on Twitter:@concentrateddon or @concentratdgreg

This work is copyright ©Concentrated Technology, LLC