Abstract
This chapter will cover how to use PowerShell to write the most robust reusable code possible. To do this, we will discuss how to use CmdletBinding in our functions. There are two types of CmdletBinding attributes: general attributes and parameter-specific attributes. The general attributes control how the overall function behaves. The parameter-specific attributes give us control over each parameter, including value validation. When a parameter is not provided, a default value is given. PowerShell defaults may not be what you expect, so we’ll cover what they are and how to handle them. We’ll also review how to define default values for parameters. Object-orientated languages support function overloading, which allows the same function name to be used with different types of parameters. We’ll discuss how to simulate this using parameter sets, and we’ll cover how to combine the pipeline with passed parameters to maximize the power and flexibility of your functions. Finally, in this age of globalization, we often need to support multiple languages, so we’ll discuss how multiple language support can be implemented easily with special PowerShell features.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2015 Bryan Cafferky
About this chapter
Cite this chapter
Cafferky, B. (2015). Writing Reusable Code. In: Pro PowerShell for Database Developers. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-0541-9_5
Download citation
DOI: https://doi.org/10.1007/978-1-4842-0541-9_5
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-0542-6
Online ISBN: 978-1-4842-0541-9
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books