Contenu connexe Similaire à PowerShell Best Practices (20) Plus de Michael Blumenthal (Microsoft MVP) (20) PowerShell Best Practices2. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.2
3. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
Agenda
3
1
2
Best Practices
Resources
4. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
Source Code Control
5. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
Function global:Do-Something($someParameter){
}
Use Functions
Modular Reusable
Commentable Safer
6. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
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.
.INPUTS What’s it take?
.OUTPUTS What’s it give?
.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.
#>
7. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
8. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
Self Announcing Functions
9. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
Follow the Naming Convention!
10. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
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
11. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
Executing Scripts
11
1
2
.filename.ps1
Set-ExecutionPolicy <Policy Name>
12. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
Demos
13. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
Resources
14. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
By Bruce Payette and Richard Siddaway, THIRD edition (2017)
15. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
PowerShell Blog
https://blogs.msdn.microsoft.com/powershell/
16. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
Microsoft Script Center
https://gallery.technet.microsoft.com/scriptcenter/
17. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
Jeff Hicks, PowerShell MVP
https://jdhitsolutions.com/blog/
18. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
SharePoint Patterns & Practices PowerShell
19. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
TechCommunity.microsoft.com
20. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
PowerShell.org
21. © 2019 West Monroe Partners | Reproduction and distribution without
West Monroe Partners prior consent is prohibited.
Please feel free to contact me at any time
MICHAEL BLUMENTHAL
O365 IT Product Manager
@michaelbl
https://bit.ly/MBB-LI
mblumenthal@wmp.com
https://Michaelblumenthal.me
Any Questions?Any Questions?
Notes de l'éditeur Single purpose
Easier to read Guess the Verb Count! Windows PowerShell in Action by Bruce Payette, V3
Bruce Payette is a founding member of the PowerShell team at Microsoft. He is a co-designer of the PowerShell language and the principal author of the language implementation. http://technet.microsoft.com/en-us/scriptcenter/