Learning PowerShell – Lesson Two

Share:
PowerShell

PowerShell Lesson Two

By: Steven Aiello

Teach Your Self PowerShell – Scripting Basics

What is a computer Script?

In general it’s my opinion that a computer script is an automated way to interact with a system shell. A shell is some sort of input/output system that interacts with the operating systems kernel. In short a kernel is the heart of an operating system. If you would like to read more about what a kernel is, here’s a link to Wikipedia:

http://en.wikipedia.org/wiki/Kernel_(computing)

In Windows the kernel is kernel32, in Linux the kernel is usually just called “the kernel”. In Linux the most common shell is the BASH shell. In windows we used to only have cmd.exe which was the default shell; however, PowerShell is quickly overtaking cmd.exe as the shell of choice for Windows administrators.

A script is something that interacts in a systematic way with your operating systems shell.

How is a Script Different than an Application?

You may ask the question how is a script different than an application? Generally an application is processing data exterior to the Operating System, and an application is generally processing data related in some way to user data. Now I fully admit this is not always the case, for example what if you install a piece of software specifically to monitor your operating system? This would certainly interact with Operating System data. However, if you look at most application packages out there like Microsoft Office or the Adobe suite, these packages process data outside the scope of the operating system.

If you would like to look at the differences in “scripts” verses “applications” in another way generally scripts are written and used by the same person or the same team. These scripts are usually designed to do something very specific on a group of systems. An application general is used for more than let’s say monitoring your MS SQL instance.

Lastly, in a simple sense, some people would define a program as something written in a language that is compiled like C or C#; however, scripts are generally not compiled and executed line by line by the shell. As you can see there’s a variety of ways to looks at applications and scripts. Much of these differences aren’t directly relevant to your use of PowerShell in this tutorial, but it is good to have an understanding of the concepts.

What is Pseudo-Code?

Pseudo-Code is a high level step by step description of what an application or script does. For example, let’s say we were to write pseudo-code for making a peanut butter and jelly sandwich pseudo-code would look something like this:

Go to cupboard

Lift arm

Grab bread

Open bread package

Remove two pieces of bread

Set bread on the counter

Put bread back in cupboard

Close cupboard

Turn to fridge

Open fridge lift arm

Grab jelly

Set jelly on the counter

Open jelly

So on and so forth..

As you can see the simple act of making a peanut butter and jelly sandwich is a very complex task when you list out every step. We take this for granted because our brain simply does what we tell it to. However, a computer has no way to inherently know what we want it to do. Because of this, it’s critically important that we map out step by step what we want our script to do for us before we ever start writing it.

What are Comparison Operators and Logical Operators?

Comparison Operators

In general you can think of comparison operators as things having to do with basic math for example:

1 = 1

1 < 2

2 > 1

1 <= 2

1 != 2

Logical Operators

Logical operators introduce more subtleties of language when we say “Steve is not the same person as Tom” we are not making a mathematical statement. We’re saying that they, as two people, are not the same. So if we were to look at logical operators we could envision them this way:

Steve is not equal to Tom

Steve and Tom are coming to the party

Steve OR Tom may show up at the party

In all honesty the computer will break down these comparison operations into math. However, as I’ve worked with students in the past this has seemed to be the easiest way for new learners to understand these concepts.

Share:

Leave a reply

forty three − thirty nine =

This site uses Akismet to reduce spam. Learn how your comment data is processed.