Chapter 15: Extending Types


Overview

PowerShell doesn't often force you to deal with specific data types. However, as you learned in Chapter 5, PowerShell does support data types like strings and integers. You can extend those types to provide customized functionality.

PowerShell's system of types is quite powerful and useful. For example, Chapter 5 introduced you to the concept of variables as objects, where a variable of the String type has methods like Replace and properties such as Length. The functionality built into these types directly from the .NET Framework that lies underneath PowerShell.

What makes PowerShell even more flexible is the fact that these types can be extended. This isn't inheritance in the true .NET Framework sense. However, it's close enough for Windows administrative purposes! For example, you can write script code that extends the String type so it has an IsEmail method. That method might use a regular expression to see if a string is formatted as an E-mail address, and return a True or False either way.

Type extensions are permanent, which means once you create them they're always available until you specifically remove them. Keep in mind that we're not making new types; we're simply adding functionality to types that already exist within PowerShell.



Windows PowerShell. TFM
Internet Forensics
ISBN: 982131445
EAN: 2147483647
Year: 2004
Pages: 289

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net