PowerShell 4.0: The 10 best new PowerShell commands

With the latest version of its scripting toolkit, Microsoft pushes task automation further into virtual machine management, configuration management, and network troubleshooting

New in PowerShell 4.0

In these days of austere IT budgets, enterprise admins typically have more on their plate than they can handle. Every task they can either delegate or automate helps turn the stress level down a notch. Microsoft stepped up the capabilities of Windows PowerShell with the PowerShell 3.0 and Windows Server 2012 releases, and the company has continued to add features and improve others in the PowerShell 4.0 and Windows Server 2012 R2 editions. In this slideshow, we'll hit some of the highlights and show you how to dig out more details on your own. 


Learning your way around PowerShell starts with the Get-Help command. The other command to help you figure things out is Get-Member, which you use when you want to view the properties and methods of another PowerShell object. New in PowerShell 4.0 is the ability to save help files to make it easier to update systems not connected directly to the Internet. PowerShell 3.0 allowed you to save help only for modules locally installed. If you wanted to get the entirety of PowerShell help, you had to install every module on your local machine. Now you can just use Save-Help and get any help you want.


This cmdlet was introduced in Windows Server 2012 and has been expanded in Windows Server 2012 R2 to add the Guest Service Interface parameter. This service is turned off by default and must be enabled either through the settings page in Hyper-V Manager for each VM of interest or by using a PowerShell command as in Enable-VMIntegrationService -Name "Guest Service Interface" "Baseline 2012 Server." We can all appreciate the ability to enable (or disable) integration services on every VM with one line of code.


Moving files into and out of virtual machines can be problematic. First you need to have the integration services installed and file sharing turned on. This requires only a single PowerShell command, Enable-VMIntegrationService. But then you have to log into the VM and copy the files to or from a network share. If you have a lot of VMs, that’s a lot of heavy lifting. Now you only need to type the Copy-VMFile command in PowerShell. It works to copy files both into and out of a VM.


Keeping servers in a known configuration state can be a challenge in any environment. With multiple administrators and the opportunity to change settings comes the ability to potentially disable any feature or function on a server. PowerShell 4.0 introduces automated configuration management in the form of Desired State Configuration. DSC uses script-based configuration files that you create using PowerShell ISE. These are then converted into MOF files that are then used to set or check the configuration of a server using the Start-DscConfiguration cmdlet. DSC is a big topic, and there are lots of cmdlets and configuration files to explore. You might want to start with this TechEd 2013 video and this TechNet article


Get-FileHash is another one of those commands you've always needed but didn't really know it. Put simply, the Get-FileHash cmdlet will compute a hash of any file or files you pass to it. You can even choose the algorithm used to compute the hash. This is especially useful for checking the consistency of large downloads, such as the ISO file for Windows Server 2012 R2. Microsoft typically provides the SHA1 file hash of all downloads, which you can now compute using this cmdlet.


Microsoft invested a huge amount of effort into new networking capabilities in Windows Server 2012 R2. You can see it in multiple places from the new multitenant VPN gateway to all of the new PowerShell cmdlets with some kind of networking term in the name. Get-NetNat is part of the NetNat module that also contains such commands as New-NetNat and Set-NetNat. This ability to configure Network Address Translation on remote machines is at the heart of Microsoft's hybrid cloud strategy, where you can connect your on-premises machines to machines in the cloud, and they communicate as if they're on the same LAN. These PowerShell commands make the creation and deletion of virtual NAT connections possible with the running of a simple script. 


Windows Server 2012 R2 Hyper-V introduces the concept of Generation 2 virtual machines. This completely new architecture includes BIOS firmware that can be updated or replaced entirely. You can use Get-VMFirmware to retrieve the BIOS firmware versions of specified VMs, and the Set-VMFirmware command to change the firmware. 


Running jobs at specific times is one of those functions every systems administrator must know how to accomplish. The Set-ScheduledJob cmdlet introduced in PowerShell 3.0 provides just such a tool for running virtually any PowerShell script at a specific time or on a pre-determined schedule. What wasn't so easy in PowerShell 3.0 was the ability to run a scheduled job immediately. PowerShell 4.0 adds the keyword parameter RunNow to make that task easier. Another new parameter for the New-JobTrigger and Set-JobTrigger cmdlets is RepeatIndefinitely for those jobs you want to start and run forever.


Troubleshooting network problems is without a doubt one of the most frustrating exercises an IT administrator must endure. Windows has traditionally provided very little in the way of built-in tools to make this task more bearable. With PowerShell 4.0, your network troubleshooting life just got a lot easier. The Test-NetConnection cmdlet combines a number of tests into one simple command plus a few parameters. For example, the command Test-NetConnection -ComputerName www.infoworld.com -InformationLevel Detailed would attempt to connect to the website www.infoworld.com and return a detailed list of diagnostic information.


It's pretty obvious that networking in Windows Server 2012 R2 received lots of attention. Virtual networking has been one of those areas that require a considerable amount of hands-on troubleshooting when things go wrong. Now you can run a series of tests on your virtual machine network adapter from the convenience of your PowerShell prompt. 

Windows Server 2012 R2 Hyper-V highlights

The next version of Hyper-V brings leaner and cleaner "Gen2" VMs, improvements to Hyper-V replica, faster live migration, online VM exporting and cloning, and lots more. Read about our 10 favorite new Hyper-V features in "10 great new features in Windows Server 2012 R2 Hyper-V."

More Windows Server 2012 R2 highlights

Not all of our favorite new Windows Server 2012 R2 features are in Hyper-V. Read about 10 excellent new features elsewhere in Windows Server 2012 R2 that will make an impact on your day-to-day operations. Some of these enhancements, particularly in the storage arena, have Microsoft taking direct aim at traditional partners with new out-of-the-box functionality.