Get schooled in advanced Microsoft PowerShell v3 cmdlets

Master class: PowerShell v3 cmdlets

The Microsoft PowerShell updates that rolled out with Windows Server 2012 clearly indicate the vendor intends to use the scripting language as an operational framework for most of its products. With PowerShell v3 cmdlets, for example, you can install and configure Hyper-V from the command line, and eventually you'll be able to perform all Hyper-V management from the Systems Center family, which runs PowerShell under its graphical user interface.

PowerShell is certainly not the only command-line shell on the market, but its capabilities reach beyond Hyper-V into VMware vSphere and Citrix XenServer management as well. You can even apply PowerShell scripting to Exchange Server 2013 and virtual desktop infrastructure management.

Given PowerShell's influence, and the industry trend toward more widespread use, now is the time to brush up on the latest changes, and learn how you can apply the scripts to your environment. Head back to virtualization school for lessons in advanced Microsoft PowerShell techniques.

Table of contents:

Lesson 1: What's new in Microsoft PowerShell cmdlets

The PowerShell cmdlets included with Hyper-V in Windows Server 2012 allow admins to run advanced scripts without System Center Virtual Machine Manager (SCVMM), which was previously needed when running Windows Server 2008 R2. This change means decreased hardware and software costs for some data centers. However, the sheer volume of cmdlets and PowerShell syntax changes may take some getting used to, and present many opportunities for error.

Rather than sorting through each command and prompt to determine which will best benefit your infrastructure, we've highlighted five of the best features in PowerShell v3, that allow you to automate more tasks than before, and easily perform remote management.

By reading about some of the more frequently encountered problems, and working proactively to prevent them, you can ensure PowerShell success.

Lesson 2: Using PowerShell v3 remoting for efficient VM deployment and replication

Remoting, introduced with PowerShell v2, was a highly anticipated new feature. It connects an administrator's local PowerShell session with a session running on a remote system.

One of the newest Microsoft PowerShell features is the ability to create a golden image that can rapidly deploy and configure virtual machines (VMs). It's also possible to automate the process with a script. You could even write this simple parameterized script as an Advanced Function, making it operate exactly like a PowerShell cmdlet.

Before you can create the golden image, however, you'll need to use PowerShell remoting to configure your servers, and if you're not using Windows Server 2012, you must enable PowerShell remoting manually.

PowerShell v3 cmdlets also enable efficient, effective management of both the Hyper-V extensible switch and Hyper-V Replica. The switch extends the functionality of the virtual network to a smart, manageable piece of hardware. It allows you to gain functionality in the network without having to build in special support or rip out the whole network. The Hyper-V Replica feature lets you replicate a VM from one location to another with without shared storage.

The terminology associated with the commands and prompts can get confusing. Some new cmdlets in v3 that replace legacy versions, so be sure you understand the nuances before you begin any advanced processes.

Lesson 3: Using PowerShell's Failover Cluster cmdlets to improve live migration

Hyper-V's Live Migration feature does not, by itself, allow you to live migrate multiple VMs at one time, or to schedule migrations. Fortunately, you can work around these limitations using PowerShell. You can use the PowerShell Failover Cluster cmdlet to automate the live migration process.

Microsoft gave the Failover Clustering feature a makeover, with 81 cmdlets that can be used to manage components from PowerShell. But the default settings and installed features have also changed. Take the time to identify what you still need to download or settings you need to enable to manage your clusters and hosts.

You can, however, also use PowerShell cmdlets to manually run certain prompts, which allows you to avoid using Live Migration altogether. In addition, certain SCVMM PowerShell cmdlets allow you to live migrate an entire host's worth of VMs to a specific node, or transfer VMs based on their Cluster Shared Volumes assignments, both of which can help you avoid disk latency and sluggish performance.

Lesson 4: Using Microsoft PowerShell for more than just Hyper-V management

As Microsoft rolled out its 2012-2013 product line, one thing was clear: PowerShell would play an even bigger management role. Exchange Server 2013 features 187 new cmdlets, including the Get-HealthReport cmdlets and the Set-ServerMonitor cmdlets.

PowerShell's capabilities also span multiple platforms and areas of virtualization -- including virtual desktop management. You can even manage virtual desktops using Windows PowerShell commands, VMware's PowerCLI or XenApp cmdlets. The command line is a useful place to perform remote monitoring and management. Before you begin, however, you'll want to make sure you've enabled Remote Desktop Management if necessary, and checked for any antivirus software that may block PowerShell access.

Finally, don't discount PowerShell as a management tool for Citrix Systems. Despite lackluster native support, you can easily download a snap-in to enable Microsoft PowerShell for XenServer management. Depending on processor and client operating system (OS) size, you may need to use a command to get PowerShell running, but the cmdlets give you Citrix XenDesktop, XenApp, Provisioning Server, Netscaler and XenServer management from a single interface. The basic scripts allow admins to assign a home server to a VM, copy VMs and determine the pool master, while the advanced scripts allow you to sort and interpret data that's collected from the OS command line itself.

Additional reading

Identifying files by date using a PowerShell filter

Making and running a PowerShell script prompt for input

Office 365 password policy changes using PowerShell

How PowerShell code can help you locate unused Exchange Server mailboxes

Using the PowerCLI Get-VM cmdlet

Five vSphere PowerCLI scripts every admin should know

Exchange 2013 public folders and PowerShell

PowerShell snap-ins for PowerCLI 5.0