in

WindowsWindows Loving ItLoving It

PowerShell for Dummies

In this post, we will show you the basics of Latest PowerShell tips and tricks. We will show you how PowerShell is integrated with .NET

PoweShell for Dummies

What is Powershell?

We will answer that by using PowerShell.

We can easily launch PowerShell by pressing the Windows key and typing powershell in the search bar.  We can immediately launch it in administrator mode by pressing the below keyboard shortcut.

ctrl+shift+enter
Launch PowerShell
Launch PowerShell

By default, PowerShell opens up in system32

system 32
system 32

We can use cd .. to go up a directory.

cd ..
cd ..
cd ..

We can use cd command to go into a directory.

cd system32
going down the directory
going down the directory

We can use cd . to get the current directory.

cd .
same directory
same directory

Use the dir command to get the details on current directory.

dir

In our case, we are in system32 and the list is pretty long.

system32
system32

We can do navigation using an absolute path also.  Below is an example of using an absolute path to get to a specific directory.

We can see that using an absolute path after cd.

cd E:\96\Images\lightshot
change directory
change directory

In PowerShell everything is a command let.  That is not a command, it is called a command let.  In PowerShell, the command let follows a structure.  It is Verb-Noun.

Verb-Noun

It is the easiest way to remember the commandlet.  Below are some of the command let that follows this structure.

get-childitem

split-path

get-history

invoke-history

We can use cls and ctrl+l to clear the screen.

clear screen
clear screen

get-child item is the command-let that gets the child items of a directory.  There are an alias that makes invoking this command let easier and some of them are

dir

ls

dir ls
dir ls

These aliases will call the get-childitem.

get-childitem
get-childitem

We can use a command-let to get the alias details for easy shorthand and the command let is:

get-alias

Let us address what happens when we shift from cmd, bash, or any other terminal.  PowerShell works with the input and the output that comes on the screen as objects.  We are working with C# .NET objects when we use the PowerShell terminal.  In the traditional terminals, the inputs and outputs are text-based but with PowerShell, the inputs and the outputs are C# .NET objects.

When we use the pipeline, we are sending the objects from one command to another.  This is very much not like other terminals.

Let us see this in action.  We will run the get-childitem command.

get-childitem
get-childitem
get-childitem

Now we will pipe it to a select and get only the name with the below modification

get-childitem | select name
select name
select name

We can also select the first or the last object using the following modifications.

get-childitem | select -first 1

get-childitem | select -last 1

The point of making this demo is to show that we can not perform the column-based selection using the select command let but we can not do it directly to get-childitem.  This is consistent with dealing with the list of objects in C#.

Note that select is actually an alias for select-object.

We can pipe on and on like the below example.

get-childitem | select -first 1 | select name
select first one name
select first one name

If this does not look like dealing with lists of objects in C# we can show a command let that brings up .NET like nature to each object.  Use the following command to get the properties and methods of each object.

get-member

The get-member will bring up the following details.

get-childitem | select -first | get-member
get member
get member

Here we can see that the different children inside.  Some of the children are of type property and some are methods.  This is also consistent with .NET.

Conclusion:

Here we learned some of the basic command lets of PowerShell and also their alias.  We can use the get-alias for getting the alias of each command. We also learned that unlike other terminals that have inputs and outputs as texts, PowerShell has the inputs and outputs in .NET objects.

We can use the get-help to get various information about all the command lets and other things about PowerShell.

For more on PowerShell stay tuned to TecKangaroo.

PowerShell for Dummies
  • Author Rating
  • Content Clarity
  • Content Relevance
  • Article Rating
4.5

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading…

0

Comments

0 comments