practical powershell tips & tricks mms minnesota 2014 trevor sullivan, jeff wouters, david...

15
Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien #MMSMinnesota #MMSConfigMgr #MMSLove

Upload: susanna-patrick

Post on 22-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien

MMS Minnesota 2014

Practical PowerShell Tips & Tricks

Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs@pcgeek86 @jeffwouters @david_Obrien

#MMSMinnesota#MMSConfigMgr#MMSLove

Page 2: Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien

MMS Minnesota 2014

Speaker Profile – David O’Brien

•MVP for Enterprise Client Management • Heavily focused on Automation• Blog: http://www.david-obrien.net • Twitter: @david_obrien• Principal Consultant at Dilignet in Melbourne

Page 3: Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien

MMS Minnesota 2014

Speaker Profile – Trevor Sullivan

• Director of Training and Product Development @ Opsgility• Likes trying new craft beers• Passionate about spreading knowledge and awareness•Microsoft MVP for Windows PowerShell• http://trevorsullivan.net•@pcgeek86

Page 4: Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien

Speaker Profile – Jeff Wouters

•MVP Windows PowerShell | BSc | MBA•MBA Psychology• Lead Infrastructure DevOps Engineer @• Scripting, Automating, darts, beer.• Blog: http://www.TheScriptingDutchman.com• Twitter: @JeffWouters

Page 5: Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien

MMS Minnesota 2014

Social Media

#PSDSC#PowerShell

Page 6: Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien

MMS Minnesota 2014

Agenda

• Prompt Function• Splatting (v3)•Where and ForEach Method Syntax (v4)• Classes (v5)• PSTypeNames• .NET Formatting• Variable Squeezing• Type Casting• Evaluations

Page 7: Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien

Splatting (v3)

• Easier to read code• Separates input data from script logic• Downside: No Intellisense for parameters

HashTable(Parameters) Command Call

Page 8: Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien

Where/ForEach Method Syntax

• Use a fluent-style syntax instead of PowerShell pipeline

Filter(Where)

Objects

Objects

ForEach

Page 9: Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien

Classes (v5)

• Create custom object types• Add properties and methods• Decorate classes with existing attributes• Lexical vs. dynamic scoping of variables

Class

Properties Methods

Constructors

Overloads

Static

Initializers

• Private class members are not supported• Inheritance / interfaces not supported• Namespaces

Page 10: Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien

PSTypeNames

• Append custom type names to existing objects• Apply a custom type to a PSCustomObject• Use the [PSTypeName()] parameter attribute to constrain

input objectsObject

PSTypeNames

PSTypeName

PSTypeName

PSTypeName

Page 11: Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien

.NET Formatting

• Value substitution• Date formatting• Numeric formatting• Custom formatters

Format String Objects

Page 12: Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien

Variable Squeezing

• Simplified syntax to assign variables and print output

Page 13: Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien

Type Casting

• Convert objects from one type to another• Explicitly declare variable types• Some types support “Parse” method instead

Int32 Int64

Page 14: Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien

MMS Minnesota 2014

PowerShell ISE Tips

• New PowerShell Tabs (Runspaces)• Invoke Intellisense• Snippets• Console vs. Script Pane• Horizontal/vertical split vs. script-only view• ISESteroids

Page 15: Practical PowerShell Tips & Tricks MMS Minnesota 2014 Trevor Sullivan, Jeff Wouters, David O’Brien – Microsoft MVPs @pcgeek86 @jeffwouters @david_Obrien

Session Title

EvaluationsPlease provide session feedback by clicking the Eval button in the scheduler app. One lucky winner will get a free ticket to the next MMS!

Visit all of our sponsors in the expo area and online!

Platinum Sponsors:

Gold Sponsors:

MMS Minnesota 2014