Why is This Useful?


So why should you care about extending the functionality in PowerShell's built-in types? The answer is modularization. For example, imagine you've written a function that tells if a string is a valid E-mail address, or a Universal Naming Convention (UNC) path, or something else. You could reuse that function by pasting it into all your scripts, but the code wouldn't be centralized. Any changes to your function would need to be manually replicated to every script containing the function. However, if you used that function to extend the String type to have an IsEmail method, IsUNCPath method, and so forth, then the functionality would be available to all of your scripts through a single block of code. True, you might need to manage multiple PS1XML files if the type extension was to be used on multiple computers. However, that's less of a burden than managing dozens of disparate scripts. In addition, if you're primarily writing scripts to run on your own computer, then you'd only have one file to manage.



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