Microsoft PowerShell can be an extremely useful tool for automating system management tasks in Windows. While most system configuration and administration tasks are typically done in Windows using GUI (graphical user interface) tools, shell scripting can be a powerful tool for automating repetitive tasks and ensuring consistency across your server environment. It can also allow you to automate actions across different applications running on Windows. If you are not familiar with PowerShell, Microsoft’s PowerShell Documentation page is a great place to start learning.
What is PowerShell?
Perhaps the simplest way to think about PowerShell is that it lets you manage computers and processes directly from the command line. It provides both an interactive shell and a scripting environment allowing you to perform tasks by simply typing commands or running scripts. This makes it easy to perform simple or even complex actions across all aspects of the system without the need to open different management console applications. In addition, PowerShell provides remoting capabilities allowing you to run commands and scripts on one or hundreds of servers from a single PowerShell command.
Most of the commands you will execute using PowerShell are implemented as cmdlets. A cmdlet is a lightweight command that performs a specific action and typically returns an object. PowerShell cmdlets utilizes a “verb-noun” naming system to express their specific actions. The verb defines the action and the noun is the object that is acted upon. This makes it easy to understand what a PowerShell command does by simply reading its name. So, the function of commands like Get-Process, Stop-Process, Get-Service and Stop-Service are readily apparent. PowerShell has a large list of cmdlets available and as an example, you can use the Get-Command cmdlet to list them all in your PowerShell window.
Microsoft provides a framework for application vendors to design and implement their own PowerShell cmdlet code. DataCore has created the DataCore Cmdlets for Windows PowerShell that bring the features and functionality of SANsymphony to the PowerShell command line interface. Today we have over 150 cmdlets available that can help administrators manage SANsymphony software directly from the command line or through custom created scripts. The DataCore cmdlets can be particularly useful for automating repetitive tasks or remotely administering your SANsymphony servers and storage.
With the ability to pipe commands together, you can perform complex actions that may take many clicks in the management console with a single command line. For instance, if you wanted to enable Continuous Data Protection for all of the virtual disks in your SANsymphony environment, you can accomplish that by piping the Enable-DcsDataProtection cmdlet with the Get-DcsVirtualDisk cmdlet in a single command as shown here:
Get-DcsVirtualDisk | Enable-DcsDataProtection -Server SSV2 -Pool “Disk Pool 1” -HistorySize 15GB
In this example, Get-DcsVirtualDisk is used to pipe all objects to Enable-DcsDataProtection. Executing this command will result in all virtual disks being enabled for Continuous Data Protection with the history log files set to a maximum of 15GB and stored on server SSV2.
How We use PowerShell to Automate Testing at DataCore
Two of the most valuable benefits of scripting with PowerShell are automating repetitive tasks and ensuring consistency of administrative actions. These are also two fundamental cornerstones of automated system testing.
As you may be able to imagine, we do a lot of system testing here at DataCore that involves deploying and configuring Windows Servers and installing new builds of SANsymphony software over and over. Using PowerShell along with the Windows and DataCore cmdlets, our automation team has created a powerful tool that enables us to automate the process of deploying Windows as well as installing and configuring SANsymphony storage.
Internally we call this tool Instant Environments and it not only allows us to quickly setup new testing environments but it ensures that every environment we create has the same consistent configuration. This gives our test teams and testing activities the speed and consistency needed to deliver high quality software as part of our agile development methodology.
In addition to automating system setup, PowerShell is also the foundation of our automated test suites for SANsymphony at DataCore. We execute thousands of test cases when developing new versions of SANsymphony and many of these tests are run over and over as part of our regression testing, a perfect scenario for automation. Using the DataCore cmdlets, we have created multiple PowerShell-based test suites that enable us to quickly and efficiently perform automated regression tests during development. This helps our engineering team develop new functionality quickly while also ensuring we keep our quality standards high.
We also utilize PowerShell to automate some of the system and stress testing we perform at DataCore that requires complex actions and long run times. Our high availability automated test suite is a good example. This test suite automates many of the common HA and fail over scenarios we test in SANsymphony like stopping a server in the group, splitting and re-mirroring virtual disks, moving virtual disks and replacing virtual disks. This enables us to effectively validate system stability and storage availability over long periods of time in a consistent and repeatable way.
As you can hopefully see from this short set of examples, PowerShell can truly be a “powerful shell” environment for automating many different aspects of Windows and SANsymphony management. If you find yourself repeating the same administration tasks over and over again, take the opportunity to learn more about automation by visiting the PowerShell github page and the Getting Started with DataCore cmdlets page. Also, be sure to check out the Microsoft Script Center which provides access to over 15,000 PowerShell Scripts developed and shared by IT professionals.