In IT, a huge number of services are provided through automation. And to be able to provide this automation, we need to create scripts. There are a number of different options for scripting languages. And we should always find the best choice for the job.
To understand which scripting language we would use, we need to look at the task we need to perform and the operating system that we’ll use to perform it. And it’s quite likely, throughout your career, you will use one or more of these scripting languages, depending on what you need to do. The fundamental scripting language of Microsoft Windows is the batch file.
This is sometimes written with a .bat file extension. And it allows you to script information at the command line of Microsoft Windows. This is a type of scripting language that has been around since the DOS and OS/2 days.
So there’s quite a bit of capability at the command line of Windows. And we can take advantage of those capabilities by using a batch file. For example, this is a batch file that runs at a Windows command prompt that moves working documents to a production environment. It looks for anything that is a doc or txt file. It performs an XCOPY from that working environment to a production folder.
And although a batch file provides us with a lot of flexibility at the command line, there are still features within Windows that aren’t available from a batch file. To be able to access those features, we need a better version of the command line. And we get that with the Windows PowerShell.
This is a command line environment that is made for the system administrator. Almost every aspect of Windows is accessible through commands available in the Windows PowerShell. These PowerShell scripts commonly have a .ps1 file extension. And you’ll find PowerShell is already available in Windows 10, Windows 11, and a number of previous versions of Windows.
The functions within these scripts are provided through commandlets. This is a series of scripts and functions that you can run with one PowerShell script. And you also have the ability to create standalone executables from a number of these PowerShell scripts. If you need to manage services on a Windows system or configure some aspect of Active Directory, you can provide access to all of that through a PowerShell script.
Windows also includes another type of scripting called Visual Basic Scripting, or simply VBScript. You’ll see these visual basic scripts with a .vbs file extension. These are commonly used as a general purpose scripting language in Windows.
For example, you can have a backend web server scripting that is done in VBScript. You might want to script something on the Windows desktop itself. Or you may be scripting inside of a number of different Microsoft Office applications using VBScript. You can think of PowerShell as providing automation to the operating system and VBScript as providing automation to particular applications.
If you need to script at the command line within Unix or Linux, then you would run a shell script. A shell script in Linux works very similar to the way that a batch file might work in Windows. These shell scripts allow us to perform a number of automation steps at the command line in Linux. And it’s very common for a Linux system administrator to use these shell scripts to automate a number of different features inside of Linux.
One way to immediately tell that this is a shell script is to look at the first two characters of the file. You’ll notice that they start with a pound sign and an exclamation mark. In the world of Linux, we call this a shebang or a hash bang. And it’s very common to associate these with a .sh file extension.
A general purpose scripting language that runs on many different operating systems is Python. Python scripts are commonly written with a dot .py file extension. The popularity of Python has really come about due to the use of automating cloud-based services, but you can use Python for any operating system to automate almost anything at the command line. If you need to write a script that will run across many different operating systems, you might want to consider using Python.