Writing Scripts

While you can use the PowerShell prompt to run cmdlets, most Windows Server 2008 administrators will write their own scripts for performing tasks in their environment. For example, you could develop a script to ping remote systems to discover whether they are available, and report on those that are not. You could extend this to time how long a ping takes and report whether that time is outside of some previously established norm, or you could develop a script to add a user to your active directory, add the users to role-based security groups, enable the Exchange and Unified messaging mailboxes, and enable the user to use the Office Communications server.

A script is a text file with a PS1 extension that contains the commands you might type at the PowerShell prompt along with a variety of control statements to control the execution of your script. In general, there is nothing you can do in a script that you could not do at the PowerShell prompt—scripts just cut down on typing. This means you can try things out at the PowerShell prompt, and create your script from there—something not really possible in traditional scripting languages such as VBScript.

For added security, scripts can be digitally signed. When combined with PowerShell's execution policy, this enables you to restrict administrators to only running scripts specifically signed by your organization. For more information about signing PowerShell scripts, see http://www.hanselman.com/blog/SigningPowerShellScripts.aspx ...

Get Windows Server 2008: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.