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.
By default, PowerShell opens up in system32
We can use cd .. to go up a directory.
We can use cd command to go into a directory.
We can use cd . to get the current directory.
Use the dir command to get the details on current directory.
In our case, we are in system32 and the list is pretty long.
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.
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.
It is the easiest way to remember the commandlet. Below are some of the command let that follows this structure.
We can use cls and ctrl+l to clear the 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
These aliases will call the get-childitem.
We can use a command-let to get the alias details for easy shorthand and the command let is:
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.
Now we will pipe it to a select and get only the name with the below modification
We can also select the first or the last object using the following modifications.
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.
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.
The get-member will bring up the following details.
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.
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