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
- ...
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.
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
Post a Comment