PowerShell Starter

 PowerShell is seriously for Everyone


I'll be honest with you all, I know enough PowerShell to get out of trouble. On the other hand, writing these blogs have really gotten me excited about how useful PowerShell can be. I have even installed PowerShell onto my Linux machine. Yes! you heard that right, PowerShell runs on more than just Windows. In fact, Microsoft has articles on how to install PowerShell on Linux and Mac OS. 

The Power... in Powershell

I have learned that the most beautiful part about Powershell is its structure. PowerShell is comprised of commands called command-let(s), and every command-let follows the same structure Verb - Noun. This makes it easier for people to remember or even guess at a new command-let. The other winning attribute of PowerShell is that it is built around objects. 

Object-oriented languages are really cool in that coding because focused on targets of interest, and each target has attributes that make it similar to another object of the same kind, but also unique in some aspects. Think about a computer. Every person and business has at least two computers on their network (network as in your wifi). As an object, every computer has:

  • A way to get on the network
  • An address to receive notices from
  • An operating system
  • ...
The list could go on, but this is how object-oriented languages work. The focus of every transaction/command is to identify the object and then manipulate different attributes of that object, even if it is to just add it to another object.

Knowing that everything in PowerShell is an object means that you already know it can be manipulated with ease and that every attribute is separate from another.  The challenge is knowing which command-let gives you access to the object's attribute of most interest. 

At this point, let's take a break from my rambling and get into an article that I think is beautifully written, and really captures the basic command-lets that will put you on a path of Powershell Mastery. 




Accessing PowerShell

Every Windows machine from Windows XP until now has PowerShell installed by default. To access PowerShell, you simply search for "powershell" from the search bar in the menu. 


As you can probably see, there are a number of PowerShell options to pick from. I recommend beginners use the PowerShell ISE option because it provides auto-suggestions. The ISE is an IDE (Integrated Development Environment) meaning that it is there to help developers program faster and with fewer mistakes through the use of auto-suggestions and a console for debugging. 

PowerShell ISE


Programming Basics

In every programming language, there are unique shortcuts or condensed ways of getting a job done. PowerShell is no different. Before getting to a few of the unique things about in PowerShell, lets start with programming concepts.

Loops

A loop makes a step repetitive. there can be many loops within another loop. The key thing to remember every loop must be told how to stop, or it will go on forever. (No bueno)

Conditions

Conditions are meant to capture a choice by the user or requirement presented by the program itself. They are used within If/else statements, switches, and loops. Example: If (1 -gt 5) {do something...}

Lists/Arrays/Sets/Tuples

Each of these items is meant to store like objects such as all numbers or all words.


PowerShell Specifics

$_ 

used during subsequent operations such as piping or sorting to represent an original object being acted upon. For example, list out all computers in the network, and for each computer get its name would use $_.name. Each instance of a computer is represented as the $_. like saying comp_1.name, comp_2.name, etc...

@()

Used to create an array. Kind of like a list. For example @(1,23,12,1,45)

@{}

Used to create a key/value pair called a hashable. This is also called a dictionary in other languages. this is used when setting values to multiple parameters for a targeted object. Like assigning both a name and time to an object. @{ name= "tester" ; date = "02/14/2022"}


There are a few more things to learn about Powershell, but we will all learn them over time. This is a journey that we are taking together


Comments

Popular posts from this blog

Working with Windows Passwords

Writing a Powershell Script