Chapter 30. Library: Building a PowerShell Library

In this chapter, you will see some useful techniques to draw on when building your own functions, filters, and scripts. The idea is not so much to give you "101 useful PowerShell scripts," but rather to build some scripts so you can see techniques that can be applied in many different contexts. First, let's look at how to get PowerShell the way you want it.

Customizing Your PowerShell Environment

There are several ways that you might want to customize the environment for PowerShell. You can use the profile if you would like every session to have:

  • Additional PowerShell snap-ins loaded

  • User-defined functions pre-loaded from a script

  • Additional .NET libraries available

  • Additional or redefined aliases

  • Additional variables predefined

  • Customized prompt behavior or window title

  • Customized colors

The profile is just a PowerShell script and, as described in Chapter 4, the execution policy of the machine needs to be set to allow scripts to run and may require the profile script to be signed. A Group Policy template file is available from Microsoft's website (go to and search for PowerShell ADM). This allows the permissions to be set centrally for particular computers or users. For example, a Group Policy object could apply to an Active Directory OU containing servers to require ...

Get Microsoft® PowerShell, VBScript and JScript® Bible now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.