Apr 04 2013

Unleash the Automation Force with Windows PowerShell

If you haven't started using PowerShell yet to manage your Windows servers, you should.

Businesses everywhere are looking to save money, and technology can help spend resources wisely. By automating the configuration, management and monitoring of Windows Servers, companies can decrease the time IT workers spend on manual maintenance.

Manual administration of servers is slow and prone to error. Automation on the other hand, once it's been thoroughly tested, makes for fast and reliable management. Do you want your business to be more agile? If so, start using PowerShell to manage your servers.

PowerShell’s Improved Automation Capabilities

The new 3.0 version of PowerShell included in Windows 8 and Windows Server 2012 includes new features that make automation more flexible, manageable and resilient.

For example:

  • PowerShell Workflow lets you create workflows to execute long-running tasks. These tasks can then be interrupted and restarted, repeated as needed or executed in parallel for more efficient server administration.
  • PowerShell Scheduled Jobs lets you run PowerShell jobs according to a predefined schedule or when an event occurs on the server.
  • Disconnected Sessions lets you start a PowerShell script or command on a remote computer and then disconnect from the computer while the task continues to run. If needed, you can reconnect to it from the same or a different computer without affecting the running command or script.
  • Delegated Administration lets you allow users with nonadministrative credentials to execute PowerShell scripts or commands that require administrative credentials.

These new features help make PowerShell automation easier to use and implement in different scenarios.

PowerShell Scripting Is Easier

PowerShell 3.0 is much easier to learn and use than previous PowerShell versions. For example, say you want to collect CPU usage and virtual memory used for all Windows processes that have "dfs" in their process name. In PowerShell 2.0 you had to do it like this:

PowerShell screenshot

Now, look how much easier the syntax for this command is in PowerShell 3.0:

PowerShell version 3.0

The old dollar sign-dot-underscore was one of the strange syntax features that often discouraged people from learning previous versions of PowerShell. But strangeness aside, it was also hard to type. With PowerShell 3.0 you don't need to use that construct, which makes PowerShell 3.0 scripts easier to write and read.

PowerShell Works from Anywhere

Have you ever been offsite and gotten an alert on your smartphone or notebook that one of your servers needs an intervention? It would be nice if you could fire up PowerShell on your mobile device and remotely perform the task. Consider your wish granted, because using Windows Server 2012, you can set up a gateway on the firewall of your corporate network that lets you run PowerShell commands remotely from any device that has Internet connectivity and a web browser.

This awesome new feature is called PowerShell Web Access, and its PowerShell command-line in the browser lets you run scripts and commands directly on remote computers. And don’t worry about security because PowerShell Web Access uses the HTTPS protocol for all of its activity. Here's a simplified diagram of how it works:

PowerShell diagram

PowerShell Is the Future

It's clear from the direction Microsoft products have been heading recently that the future of Windows platform administration is PowerShell. For example, many of the latest graphical user interface tools for managing Windows servers are actually GUI shells that leverage PowerShell commands under the hood to perform your management actions.

A built-in example of this is the Active Directory Administrative Center (ADAC) in Windows Server 2012, which not only executes PowerShell commands from chosen menu options but also includes a PowerShell History Viewer that lets you view the PowerShell commands used to perform selected menu actions.

For example, the screenshot below shows the PowerShell commands executed when I used ADAC to create a new user named Karen Berg in the Seattle Users organizational unit of the corp.contoso.com domain in a test environment I set up for a book I was writing:

ADAC users

In this PowerShell History Viewer I can copy these commands to the clipboard and use them to create a script for automating the bulk creation of users in Active Directory. By seeing how ADAC formats these commands, I can quickly learn more about the syntax of various PowerShell cmdlets like New-ADUser, Set-ADAccountPassword and so on.

In essence, PowerShell History Viewer is both a rapid-development tool that makes scripting easier and a learning tool that helps users master PowerShell syntax.

Where Can I Learn More?

A good starting point for learning more about PowerShell is the Windows PowerShell Survival Guide in the TechNet Wiki. This wiki covers everything from where to find useful guides and videos to how to make sure your PowerShell scripts are secure.

For more information about the new features in PowerShell 3.0, see the What's New in Windows PowerShell 3.0 topic on TechNet.

Another good place to learn about the new simplified syntax in PowerShell 3.0 is Ed Wilson's article in his Hey, Scripting Guy! Blog. MVP Keith Hill also has an excellent article about this in his blog.

If you want to use PowerShell Web Access, you can learn how to deploy it using the procedure on this TechNet page. MVP Anil Erduran also illustrates a walkthrough of installing and using PowerShell Web Access on his blog.

Finally, PowerShell 3.0 is also available for Windows 7 SP1, Windows Server 2008 R2 SP1 and Windows Server 2008 SP2. To get PowerShell 3.0 on these down-level platforms, simply install the Windows Management Framework 3.0 from the Microsoft Download Center.


Learn from Your Peers

What can you glean about security from other IT pros? Check out new CDW research and insight from our experts.