Powerful PowerShell Guide for Beginners on Windows

What is PowerShell?

In simple terms, you can think of PowerShell as a powerful environment to solve problems in few lines.

Sometimes, Less is More

-William Shakespeare

Welcome to PowerShell, a stunning product from Microsoft that helps you in many ways. Are you new to coding and feel the pain of typing many lines just to print “Hello World”? Here, you need to type “Hello World” to print Hello World. As simple as that.

This article is focused on helping aspiring coders learn coding through PowerShell in a single blog.

This article shares few secret tips that were used in my Corporate training. Read till the end and you can gain access to interesting scripts to test on your machine. It would be great if you have Windows to practice.

Why Learn PowerShell?

  • PowerShell helps you to have a great marketable skill for 2021 and beyond.
  • Many IT Administrators are forced to learn PowerShell
  • PowerShell can be greatly helpful for business owners or Directors of organizations wanting to analyze thousands of data and want a report in a single click.
  • If a table with a single leg has one source of a leg gone, it falls. If a table with multiple legs has a problem with one leg, it can still stand. Knowing an extra skill gives you the freedom to work on multiple sources of income. At least 5 technical skills are recommended.

My Experiences with PowerShell

I, Thangu have been working on various software products like SharePoint, HTML, .NET, BASIC since 1995. PowerShell came like magic to help administrative tasks much easier. Slowly, it made coding works also easier. My first Corporate training was for PowerShell in various batches for over 100+ students. 

Let me share the pains of learning non-PowerShell topics:

  • Installation for topics like SharePoint take weeks
  • Software like Azure needs your credit card information to practice
  • Mastering other topics need my 300+ videos

Among various topics I have trained, I prefer PowerShell over various topics for the following reasons:

  •            No complex installation
  •            Learning PowerShell is easy and fast
  •            Thousands were happy with my simple PowerShell course with just a few videos 
  •            This helps many to code by mastering just a few concepts.
  •            PowerShell reduced my time to create scripts with its power to automate.

I have been using PowerShell for over 10+ and years and have enjoyed the following benefits:

  • Friendly creator Jeffery Snover.
  •          Automate my business tasks
  •            Create certificates for many students
  •            Draw nice drawings. See sample below:
Thangu Consulting Xmas Code
  •            Many organizations benefitted from my scripts to analyze data and take critical decision
  •            Many blog readers from my Google blogs were benefitted from my scripts
  •            Cost is cut by 90%
  •            The effort is to cut by 90%

Step by Step Guide to learn Powershell

We will have a look at the following Steps:

  • Environment Set Up
  • First Hello World
  • Mother Command
  • Top Secret to Code without Google
  • Variables
  • Loops
  • Function
  • Interesting Script

Environment Set Up for PowerShell

If you are a beginner, I recommend PowerShell ISE or just launch PowerShell.

If you have VS Code, you are free to use that too to practice.

Start->Search For PowerShell -> Launch Windows PowerShell or ISE

First Hello World

Your first Hello World code is extremely simple.

Type “Hello World” and see the results.

You can do simple calculations.

Try simple calculations like 4GB/720MB and post the answer in the comment below.

A text file is saved as “sample.txt”. Similarly, a PowerShell file is saved as “simple.ps1”

Mother Command

PowerShell consists of commands called Cmdlets or Commandlets and the mother of all commands is Get-Command.

It is of the form Verb-Noun. Imagine you want to get all running processes in computer, the command is Get-Process

Top Secret to Code without Google

You need to remember only the following commands in PowerShell.

Get-Command

Get-Help

Get-Help -examples

Let’s say you are searching for a command that shows current date on your computer

Even if you do not remember the command name, search for the command using

Get-Command *date*

Once you find the command that meets your needs, 

Get-Help Get-Date -examples

Test the examples by actually executing them

Variables

Variables help to store data in meaningful locations on a computer. This is similar to the address you live in. 

The variable starts with the $ symbol.

For Example, if you want to store a name, you can use the following

$usrName

Arrays

You can assign values to variables

$usrName=”Tom”

Multiple assignments are very easy.

$a=$b=$c=10

$sum=$a+$b

Guess the value of $sum and comment your answer below.

Multiple Arrays

A variable that holds multiple values is called an array. 

Declare an array separated by commas

$a=1,2,3

In case you want to declare an array with values from 1 to 100

$a=1 .. 100

Pipelining

This is a nice feature that sends the result from one command to another.

Let’s take an example.

You want to list all properties of the current date.

Get-Date | select *

Loop

Looping is a powerful feature.

This feature helps a task to be repeated many times. Below is a script that displays 1 to 4 using for loop.

Many automation is possible due to this simple feature.

Your Commands

You can create your commands with the help of the Function feature.

Let us say, you want to create a function that displays abc.

You start with the function keyword

Then, type your function name.

Sample below

function DisplayABC{
"abc"
}

After writing the function , how do you invoke the function?

DisplayABC

Interesting Script

Below is an interesting script to speak the Text. Try it an see!

function Speak-Text ($text) {
  (New-Object -com SAPI.SPVoice).Speak($text) | Out-Null
}

function Speak-Text {
 param ($text)

  (New-Object -com SAPI.SPVoice).Speak($text) | Out-Null
}

Speak-Text 'Hello, I am hungry!'

You can find more useful scripts to practice from here

Summary

You have learned what is PowerShell and Why Learning PowerShell is the need of the hour. With this knowledge, you learn not only to code but to do more with less. It is a journey and it takes time. Would you be interested to start your PowerShell journey? Share your thoughts in the comment below. If you are facing any issues in the Coding and do not know where to start or have queries, you can join the Telegram group here 

Do you want to upskill? Do you need useful secrets to succeed in Software Industry, Subscribe.

If you enjoyed this post, do share your experience in the comments below. Need an eBook or Video Course that guides you Step by Step With Practical exercises to practice PowerShell and learn?

Leave a Reply