Language choices (Python/PowerShell)

Moving ahead, armed with the knowledge of how to write a program and an understanding best practices, we will now look at some scripting languages that suffice for our automation scripts. A basic difference between a scripting language and a programming language (such as C and C++) is that a scripting language is not compiled but interpreted through the underlying environment in which it is executed (in other words, a converter is required to convert the commands written in human-readable format to machine format by parsing one line at a time), whereas the programming language is primarily compiled and hence can be executed in multiple environments without the use of any specific underlying environment or requirements.

What this means is if I write a script in Python, PowerShell, or even Perl, I need to install that specific language in order to run the program or script that I have written. C or C++ code can be compiled to make an executable file (.exe) , and can run independently without the installation of any language. Additionally, a scripting language is less code-intensive, which means that it can automatically interpret some of the code written in a program depending on how it is called.

Let's consider an example. Here's how we declare a variable in scripting language:

x=5

OR

x="author"

OR

x=3.5

Whereas in a programming language, the same type of declaration would be made like this:

integer x=5
String x="author"
Float x=3.5

This states that depending on the value we assign to the variable, the variable type is automatically identified in an scripting language, whereas in a programming language the declarations are tightly controlled. In this case, if we declare a variable as a String, this clearly means that we cannot declare any other type of value in that variable unless we explicitly change the data type of that variable.

We have primarily three types of scripting language that are popular for creating programs and are mainly used for automation scripting or programming. These are Perl, Python, and PowerShell.

With support for the oldest language, Perl, diminishing, the focus is now on Python because of its open source support and on PowerShell because of its Microsoft, or .NET environment. Comparing both languages is not ideal because it's up to the reader which programming language they use to write their programs. As we have more than 70% of computers running Windows, and with a growing market of Microsoft Azure as a cloud operating system from Microsoft, PowerShell is the preferred language owing to the underlying .NET environment. As we create a program in PowerShell, it is easy to port that program and execute it on another machine running Windows without any special settings.

Python, on the other hand, is growing in popularity because of its open source approach. There are thousands of developers who contribute to enhancing Python by adding special functions for specific tasks. For example, there is a function or sub-program, called Paramiko, that is used to log into network routers. Another one is Netmiko, which is an enhanced version of Paramiko that is used to log into network devices based upon network hardware vendor and operating systems (such as Cisco iOS or Cisco NXOS). Python needs to be installed before writing a Python program and successfully executing it.

Going forward, our focus will be on Python, with additional tips and tricks on how to perform the same tasks using PowerShell instead of Python.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset