alex_aldo - Fotolia

Get started Bring yourself up to speed with our introductory content.

These IT automation scripts take little effort and save a lot of work

Doing IT by hand is doing it wrong. Whether to provision components, research an issue or report on performance, IT automation scripts are powerful and easy to write.

IT administrators are under pressure to do more with less: less time, fewer resources and never enough money. Automating steps for servers and application deployments can lift some repetitive tasks off their lists.

Deploying and managing IT environments without automation is the wrong way to work. Automation scripts are no longer nice to have on the job -- they are a business necessity.

The big secret is that scripting for automation isn't complicated. These three simple scripting automation examples show typical usage scenarios that automation improves, saving time and money.

Commissioning and configuring hosts

IT administrators frequently build hosts: a time-intensive manual process, even when simply setting up a post-VM configuration. Manual setup leaves room for error; even in a small environment, it can result in subtle differences in configurations between hosts that were supposed to be identical.

The cure is desired state configuration (DSC), which programmatically defines how a machine should look post deployment. Chef is one popular DSC tool, and is used in this scripting automation example.

Although these are trivial scripting automation examples, they turn real chores into really simple tasks.

The administrator writes a Chef recipe that is held in a cookbook, which is the tool's terminology for a script in a folder with some extra layouts and configuration details.

It takes time to create an initial set of recipes and cookbooks, but the results pay back this investment. To hone and develop the deployment becomes a simple case of deploying the appropriate recipes after the initial host build. An administrator can copy, change and deploy the recipe or cookbook again and again, saving time and ensuring a consistent platform configuration.

Skeptical that setting up a DSC environment is alleviating work rather than creating new work? Consider the time it takes to set up web servers for test, development and production -- a simple script configures a web server in the time it takes to pour a cup of coffee.

Chef and its underlying language Ruby, along with PowerShell, make setting up a web server on Windows systems as easy as:

powershell_script 'Install IIS' do

 code 'Add-WindowsFeature Web-Server'

 guard_interpreter :powershell_script

 not_if "(Get-WindowsFeature -Name Web-Server).Installed"


The code above, borrowed from Chef, illustrates the simplicity of working with DSC automation. The administrator could further add web content and configuration; it's easy to copy the recipe and install a new role.

DSC and other initial deployment tools enable IT organizations to build a scalable infrastructure. To deploy the same configuration repeatedly from development through to production becomes trivial, and it reduces the risk of configuration errors creating issues when new releases occur. Similarly, an administrator could configure dozens of different configurations, depending on needs, in a controlled and documented manner.

Some IT organizations will pair the desired state configuration management tool with an orchestration tool, but even without such tools automation scripts provide an effective way to configure and manage an environment.

Information extraction and reporting

Scripting for automation aids in research as well. An administrator gets frequent ad hoc queries such as "Which hosts are my virtual machines on?" or "Who has the virtual machine administrator role?"

Reporting base facts on a group of machines can be as simple as:

$vmsToCheck = "get-content c:\scripts\vmdata.txt"

foreach ($vm in $vmsToCheck) {


    get-vm $vm | select vmname, vmhost, NumCPU, RAM | export-csv "c:\data\result.csv"


The above -- a PowerShell script used to report virtual machine status -- is about as simple as an automation script gets.

This automation script example, which took less than two minutes to write, reports on a group of machines in the vmdata.txt file. It saves time whenever users or server owners ask the administrator for machine details. Instead of researching and writing up a report each time by hand, the administrator simply inputs those twenty or so machines to report on and runs the script to generate a report.

In another example, the administrator can check the status of VMware tools for a set of virtual machines:

foreach ($VM in Get-Content c:\scripts\toolslist.txt) {
 get-vm $VM | % { get-view $ } | 
 select Name, @{ Name="ToolsVersion"; Expression={$}},@{ Name="ToolStatus"; Expression={$_.Guest.ToolsVersionStatus}}| Export-Csv -Append -Force -NoTypeInformation C:\scripts\toolsinstalled.csv 

Although these are trivial scripting automation examples, they turn real chores into really simple tasks.

Author's note: Both of the PowerShell scripts above require that the user connect to a VMware vCenter server before running, or that the vCenter connection is included in the script.

Automated reporting

Sometimes the reporting available from within an application doesn't cut it. Automation scripts give an administrator access to more advanced data when combined with the power of RESTful APIs.

Although a bit more complex than an average script, the RESTful language lets administrators import data from web-based systems via HTTP requests. With a supported API and scripting skills, an administrator can generate reports or other outputs that satisfy exact requirements. For example, I use a script to export error reports from a system that isn't good at recording them. Using the RESTful API, I created an error log that can be scraped for data as needed.

Scripting for automation is essential in today's automated IT world, as these examples illustrate. If you haven't already started to script and automate, jump on it now.

Next Steps

Sit down with this guide to REST

Experts weigh in on what networking tasks to automate

Get the comprehensive guide on automation

Dig Deeper on Real-Time Performance Monitoring and Management

Join the conversation


Send me notifications when other members comment.

Please create a username to comment.

I need to extract information from an excel spreadsheet and place it into a text file but in a very specific format. Does anyone know of such a automated script that could accomplish this?
What kind of standard IT tasks do you think you could automate in your organization?