An Introduction To PowerShell Part 1.
Tags: webdev, tutorial, programming, beginners
Published: 2023-04-27 11:50:48



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/71lo6p6rke44w23vnpv6.png)



## **What Is PowerShell:**

In a simple term, PowerShell basically is an interactive command-line environment built on .NET Framework which automates tasks that are supposed to be repetitive, long and most probably annoying. You can execute programs known as "SCRIPT" which contains various cmdlets (classes, methods, objects, types, etc.)

NOTE: Before we proceed, note that PowerShell is not case sensitive so you can either type in caps or small letters.





## Cmdlet In Details:

A cmdlet is a command through which we carry out an action in the PowerShell environment. PowerShell follows a verb-noun naming system, i.e. A command must have a verb(what it dose) and name (what it's called), some instances are: Get-Help, Get-Process, Get-Member.

Theses are some of the commands available in PowerShell:



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/12fuzcejd35s8td9yyhf.png)


A class is a parameter for an object. Classes describe how an object should look like and the things it can actually do & how to create one.

Below is an illustration of how to create a class in PowerShell:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9k28ixawoadsrwa8bu24.png)




## Objects:

Objects are basically the cmdlet representation of actions we want to automate in PowerShell; objects are usually classified into two: properties (which explains the attributes of what the object is representing) then once again, we basically methods (these are basically blocks of code that carry out specific actions as we discussed above ). In order to create an object, we could use the type accelerator [] which represents the class, then followed by a default function that comes with every class called new().



## Types:

basically, types are part of the description of an object. This basically means that a type is a description of what properties or members an object must-have. For instance, if we run a Get-Process, we get a bunch of objects, and these objects are "processinfo type of objects". Meaning the type of process that the computer is currently running & they all have the same properties. Here's a breakdown of PowerShell itself: Core Language Runtime (CLR) - .Net - Libraries - PowerShell - PowerShell Modules.

In summary: types are the definition of all members of an object.

A type contains objects, the object contains properties.

To represent a type in PowerShell, follow this syntax: [include your type in here]

For instance, to reference a sting type we would do it this way: [string]. We could still store values in this way:

 $a(you could use anything in place of a to store value. In this case I chose a) = 'joe, ball, game'

 [string]$a ($ takes the data's stored in a and then converts it to a string, this is called casting)

Typing these on a single line we have: $a = 'joe, ball, game '
 [string]$a then press the enter key.

If you have a type you ain't familiar with, you can run: $a. GetType()



## Note Properties:

Note properties are created by PowerShell, they do not have any specific type and can fit in anywhere you put them.



## Properties:

These properties have a specific type and name, they have restrictions that allow only the appropriate types in.



## METHODS A.K.A FUNCTIONS:

Are simply a block of code that does a specific action. Methods allow us to perform some action on a certain object, just like properties methods are shared across types, i.e every process has the same process methods, every file object has the same methods etc.

Just like commands, methods can have parameters on them.

The parameters of a method only take in specific types.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g7whstn5tcsfsznnshxv.png)


## Now Let's Discuss The PowerShell Environment (PowerShell lSE vs PowerShell )

PowerShell ISE is basically a graphical user interface (GUI) that enables us to execute, create and modify commands & scripts. PowerShell. Meanwhile, The PowerShell is an environment or command line interface (CLI), where we can write and execute our code.

Here is what a PowerShell ISE environment looks like:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5wgtw77x9p1kc518c132.png)

Here's what a PowerShell environment looks like:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a1l7mo41m6v0xrefzbag.png)



## Variable:

In general terms, a variable is a unit of memory in which data are stored. In PowerShell, we can represent a variable by writing it out this way: $a = 1, $4 = $4.00 "john". What this means here is that any character that has "$" before it, becomes a variable.



## Data Types Available In PowerShell:

They include integers, strings, floating-point values or decimals, Booleans and datetime values. The GetType method returns the current data type of the given variable.



## Data Types Available In PowerShell:


They include integers, strings, floating-point values or decimals, Booleans and datetime values. The GetType method returns the current data type of the given variable.



## Integers:


They're whole numbers, any available decimal gets rounded off.



## Strings:


They're a set of characters or alphabetical letters.
Floating Point Value Or Decimals:
They're decimal values.

## Booleans:

They're values that can either be true or false.

## Datetime Values:

They're values that typically contain time.

Note: variables may as well be converted from one type to the other by "explicit conversion".

## Arrays & Hashtable:

Arrays are used to store a list of data or values, it could be of any data type and they're mostly similar. Hashtable, on the other hand, is a more advanced form of array that is used in storing data that is related to each other and mostly complement each other.

Here's an array declaration:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/350xi14rkp1488xmsmix.png)

Here's a hashtable declaration:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dglbxl0dmzewl043mwj3.png)

There are lots of things that I know I didn't cover in this series, however; I would do my best to put out another breakdown series where I talk about so many terms in the simplest form possible but until then please refer to get-help cmdlet, try to read it through it's not really that long:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tm0n6g7ghw2k3o8kdhta.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nfjc5evddhg8ix14okry.png)

To access the web browser, type in: get-help get-help -online in your PowerShell environment and hit enter or simply go to your browser and copy and paste this link :


[](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/get-help?view=powershell-5.1&WT.mc_id=ps-gethelp

)