How Windows PowerShell Aids Productivity & Automation

March 10, 2016 Security and Compliance, MOVEit

Often thought of as cmd.exe on steroids, Windows PowerShell is more than just a shell. Despite its name, it actually offers personalized scripting, advanced automation and productivity solutions for administrators and power users. Others are content with the standard command prompt, batch files and perhaps the Task Scheduler that allows basic functionality. With PowerShell much more is possible, as it acts as a bridge between other supporting technologies so users can work easily with .NET, COM, WMI, XML and Active Directory.

Once powershell.exe is launched (update it and install the .NET framework first), you should be ready to create scripts or run standard tests. Keep in mind cmd.exe commands will work within Windows PowerShell, but as admins go beyond simple ping and ipconfig commands, PowerShell proves to be an ideal solution because all their existing knowledge is still valuable. In addition, the language is C#, which is a combo of C+ and Visual Basic that you'll pick up quickly when writing scripts created as a standard text file with the extension .PS1.

A Time Saver

Fundamental activities that normally require a third-party application are just as easy within PowerShell. If working on files, for example, you can view the content, search for a pattern or replace text. You can also check the list of files altered by a recent update, manage binary files, determine file encoding type, import and export structured data and much more.

Other common tasks include reusing created code and working with offsite files online or via FTP. But it's in the administrator role that PowerShell is most valuable. Scenarios wherein PowerShell saves time include but are not limited to:

  • Finding all files modified within a specific time frame. Impossible to achieve in a standard environment, the PowerShell equivalent is two lines in length and can aid diagnostics when tracking down the source of an error.
 $compareDate = (Get-Date).AddDays(-30)
Get-ChildItem -Recurse | Where-Object { $_.LastWriteTime -ge $compareDate }
  • Verify file integrity by comparing the MD5 or SHA1 hash of files on a good system with those on a suspect system.
  • Debugging a running process.
  • Listing and sorting services.
  • Importing users in bulk to the Active Directory. Though normally a tedious task, in PowerShell a CSV text file stores the data and a container holds the user accounts.
  • PowerShell Remoting allows the creation of fully automated workflows. Anything that is working on a local system can be rolled out company-wide.
  • Respond to automatically generated events. If one of your users' computers has "laid an egg," you need to know about it. PowerShell allows for the automatic creation of event triggers and responses.

Pick Your Poison

Scripting, use of cmdlets, workflows and identifying opportunities for automation are at the sysadmin's discretion, as every company or network will have different requirements. The aim is to reduce time and automate common tasks as much as possible. If you'd like to receive daily ping tests from every IP address on your network at 9 a.m., automate it using Windows PowerShell or use the cmd.exe to do it one device at a time. The latter is more tedious. The choice is yours.

Full disclosure? Script creation from scratch isn't even necessary. There are several public online sources available where scripts are ready to download and test before use. Prominent ones include the Microsoft Script Center (which also has a series of webcasts and tutorials) and the PowerShell Code Repository. Some useful scripts within these sources allow you to:

  1. Receive a ping alert script from Simon Edwards, notifying you of failed pings and again when the problem is resolved.
  2. Obtain product keys of local and remote systems.
  3. Export Active Directory Users to CSV.

Regardless of the system administration task, it is likely that Windows PowerShell can help you. Identify the time-consuming tasks that exist now and check if PowerShell can reduce the time involved. If a script isn't readily available for a complex task, take the time to create one. A created script is always reusable, and it's best to think of long-term gains rather than a quick fix.

 

Michael O'Dwyer

An Irishman based in Hong Kong, Michael O’Dwyer is a business & technology journalist, independent consultant and writer who specializes in writing for enterprise, small business and IT audiences. With 20+ years of experience in everything from IT and electronic component-level failure analysis to process improvement and supply chains (and an in-depth knowledge of Klingon,) Michael is a sought-after writer whose quality sources, deep research and quirky sense of humor ensures he’s welcome in high-profile publications such as The Street and Fortune 100 IT portals.

Read next The PowerShell Script Orchestrator