28

PowerShell Best Practices and Resources

Embed Size (px)

Citation preview

Page 1: PowerShell Best Practices and Resources
Page 2: PowerShell Best Practices and Resources

PowerShell Best Practices and ResourcesMichael BlumenthalPSC Group, LLC

Page 3: PowerShell Best Practices and Resources

Who is Michael Blumenthal?• Technical Solution Evangelist at PSC Group

• Office 365 MVP

• Dev/ITPro Mix

• In IT Consulting since 1995

• PowerShelling since 2007

Page 4: PowerShell Best Practices and Resources

• Anyone used PowerShell before?

• Who’s done scripting before? Windows? Unix?

• Developer or Administrator?

This is about you

Page 5: PowerShell Best Practices and Resources

Best Practices

Page 6: PowerShell Best Practices and Resources

Use FunctionsFunction global:Do-Something(){}

Function global:Do-Something($someParameter){}

Function global:Do-Something{param ([type]$someParameter=$(“Default

Expression”))}

Page 7: PowerShell Best Practices and Resources

Follow the Naming Convention!

Verb-Noun

• 98 Verbs

Page 8: PowerShell Best Practices and Resources

Comment your functions<#.SYNOPSIS –a brief explanation of what the script or function does..DESCRIPTION – a more detailed explanation of what the script or function does..PARAMETER name – an explanation of a specific parameter. Replace name with the parameter name. You can have one of these sections for each parameter the script or function uses..EXAMPLE – an example of how to use the script or function. You can have multiple .EXAMPLE sections if you want to provide more than one example..NOTES – any miscellaneous notes on using the script or function..LINK – a cross-reference to another help topic; you can have more than one of these. If you include a URL beginning with http:// or https://, the shell will open that URL when the Help command’s –online parameter is used.

#>

Page 9: PowerShell Best Practices and Resources

Search for Commands

Refresh the command list

Actions you can take

Page 10: PowerShell Best Practices and Resources

Self Announcing Functions

Page 11: PowerShell Best Practices and Resources

Source Code Control

Page 12: PowerShell Best Practices and Resources

•Always read scripts before running them

More Good Ideas

Page 13: PowerShell Best Practices and Resources

•Always read scripts before running them•Make yours safe when others don’t

More Good Ideas

Page 14: PowerShell Best Practices and Resources

•Always read scripts before running them•Make yours safe when others don’t•Check for valid parameter values • get-help about_Functions_Advanced_Parameters

More Good Ideas

Page 15: PowerShell Best Practices and Resources

•Always read scripts before running them•Make yours safe when others don’t•Check for valid parameter values • get-help about_Functions_Advanced_Parameters •Do error handling • get-help about_Try_Catch_Finally• get-help about_CommonParameters • -ErrorAction and -ErrorVariable

More Good Ideas

Page 16: PowerShell Best Practices and Resources

More Resources

Page 18: PowerShell Best Practices and Resources
Page 19: PowerShell Best Practices and Resources
Page 20: PowerShell Best Practices and Resources
Page 21: PowerShell Best Practices and Resources

JEFF HICKS

Page 22: PowerShell Best Practices and Resources
Page 23: PowerShell Best Practices and Resources

Find Chris JohnsonMVP

Lounge

Thursday, 9/29

4pm-5pm

Page 24: PowerShell Best Practices and Resources

http://bit.ly/pscmeComplete the form and I will send you my Comment Block template.

Page 25: PowerShell Best Practices and Resources

Join the conversation on the Microsoft Tech CommunityTHR2078 – Master PowerShell Basics: Resources and Best Practices

http://bit.ly/THR2078

Page 26: PowerShell Best Practices and Resources

From your PC or Tablet visit MyIgnite at http://myignite.microsoft.com

From your phone download and use the Ignite Mobile App by scanning the QR code above or visiting https://aka.ms/ignite.mobileapp

Please evaluate this sessionYour feedback is important to us!

Page 27: PowerShell Best Practices and Resources

Write Better Scripts starting today!

In Review…

Page 28: PowerShell Best Practices and Resources

© 2016 Microsoft Corporation. All rights reserved.