What is PowerShell? Here's the Complete Explanation

What is PowerShell? Here's the Complete Explanation

What is PowerShell? Here's the Complete Explanation

 What is PowerShell? PowerShell is a type of command line interface that supports object-oriented programming techniques in Windows. PowerShell is often used by administrators working with Windows Server operating systems to run various network setup routines on Windows-based servers. In addition to providing API (Application Program Interface) features that can be accessed by other applications, PowerShell is actually a .NET framework product that can be executed on several types of OS that produces output in .text and .net formats.

The difference between PowerShell and CMD

The main difference between PowerShell and CMD (Command Prompt) are commands known as cmdlets which are useful for setting up the registry to Windows Management Instrumentation (WMI) settings. Because it is similar to a programming language, PowerShell can work on a more complex set of commands than CMD.

PowerShell Features

The features in PowerShell are very useful for network administrators when working with Windows-based servers, including the following.

1. Scripting

This feature supports object-oriented programming mode making it easier to access by other applications.

2. Cmdlets

This feature supports server configuration settings such as running services, process management, logs, and registry management.

3. Simplified

Consistency of calling PoweShell features in the command line with GUI navigation features makes it easy for users to remember them.

4. Powerful object manipulation capabilities

Accessed and configured objects can be manipulated via PowerShell or Windows GUI tools.

5. Extensible Interface

Applications or software developed by vendors can access and take advantage of the PowerShell API features

Things To Know In PowerShell

1. Get to know PowerShell

a. Run PowerShell, click the Windows PowerShell icon on the taskbar or click Start – Search – type PowerShell

b. To display the command prompt list help, type help * then Enter.

c. Press enter to prompt to display a list of helpers or a space to enter the next page. Press the Q button to exit help mode.

d. Type the Help Get-Command command to view help information for the Get-Command cmdlet command

PS C:\Users\Administrator>Help Get-Command

e. To display the Get-Command cmdlet command details on the screen, type command.

PS C:\Users\Administrator>Help Get-Command -Detailed

f. The detailed information content of the Get-Command cmdlet can be displayed with a command

PS C:\Users\Administrator>Help Get-Command -Full

g. The Get-Help About command is very helpful for administrators in finding and displaying a list of commands that can be used in PowerShell.

2. Displays a List of PowerShell Commands

a. To display a list of commands available within PowerShell, type the following command.

PS C:\Users\Administrator>Get-Command

b. Actually you don't need to memorize one by one command in PowerShell, just type a few characters first then press Tab, the system will automatically display the fixed command. For example the Get-C command, then press Tab. PowerShell will complete the command automatically, you only need to choose the command that suits your needs. Press Tab if you haven't found the right command, if so, press the Enter key.

3. Format In Filtering Output

In this step, you will learn how to use command and cmdlet parameters to filter data. To display a list of services installed on the computer, type the command.

PS C:\Users\Administrator>Get-Service

The command feature in PowerShell functions to manipulate services starting from Get, New, Restart, Resume, Set, Start, Stop, and Suspend. To display this feature, type the command Get-Command -Noun Service

4. Various PowerShell Commands With Their Functions

No Command Function

1 Get-Service Spooler To display a list of service spoolers

2 Get-Service M To display a list of all services starting with the letter M

3 Get-Service M* | Format-List To display a list of all services starting with the letter M with detailed information on each service

Get-Service M* | Format-Custom To display a list of all services starting with the letter M complete with detailed information on each service that is running with a different view than the Format-List

Get-Service M* | Where-object ($_.Status -eq “Running”} Displays a list of running services starting with the letter M


a. Where-Object, a command to filter input

b.{}, separate script code in PowerShell

c. $_ is an input reference object )all services starting with letter M)

d. -eq is a specification parameter, in this case it will compare the state of the service status under running conditions

Get-Service M* | Where-object ($_.Status -eq “Stopped”} Displays a list of services in a stopped state starting with the letter M

Get-Service | Sort-Object Status Displays a list of services in the machine complete with their status

Get-Service | Sort-Object Status | Format-Table _GroupBy Status Name, DisplayName Displays a list of services in the complete machine with their status grouped by each service

5. Displaying object metadata

Every PowerShell object is basically .NET based which references cmdlets, services, and processes that aim to ease server administration. The following lists the commands that can be used to display object metadata information in PowerShell:

a. Get-Service | Get-Member is used to view the metadata type of each object generated by the Get-Service command.

b. Get-Process | Get-Member is used to display the metadata type of the object generated from the Get-Process command.

c. To create a new object of type System.Diagnostics.Process and display its metadata, type the command

PS C:\Users\Administrator>New-Object System.Diagnostics.Process | Get-Member

d. Type the command Get-Service Spooler | Select-Object ServiceDependedOn to display a list of spooler services that have a dependent on status.

6. Using the Show Command

PowerShell provides a graphical help feature to display detailed information for a command.

a. Use the Show-Command commands to display the help window.

b. To further filter information about a command, use the Show-Command [cmdlet] format command, for example.

PS C:\Users\Administrator>Show-Command Get-Service

Show PowerShell Commands

c. The output list of services running on the server can be shown with the Get-Service -ComputerName Localhost command.

7. Command Whatif And Confirm

PowerShell also provides permission for network administrators to safely test and learn commands in PowerShell (simulating). In this exercise, the techniques for using whatif and confirm commands will be explained.

a. The whatif command is used to simulate or display the effects or effects generated when running a certain command in PowerShell. For example, to display a list of services (starting with the letter M) that will be stopped when running the Stop-Service command, use the Stop-Service M* -whatif command.

Whatif PowerShell

b. The Confirm command will give a warning about the impact of the operation being executed. An example of a Confirm command is Stop-Service M* -Confirm. At that command, PowerShell will ask whether the command will be executed or not, press Y to continue

Confirm PowerShell

8. Creating Variables in PowerShell

As in programming materials, variables are temporary storage memories to hold certain data before reuse. Here are the steps you need to know.

a. Creating a variable with a data value of type string, see the following example.

PS C:\Users\Administrator>$text = “Hello, this is a powershell string variable”

b. How to display the contents of a text variable is with the command.

PS C:\Users\Administrators>$text

Hello, this is a powershell string variable

PS C:\Users\Administrator>Write-host $ text

Hello, this is a powershell string variable

By default, the value of every variable in PowerShell is Null which is represented by $null.

PowerShell variables

c. Each variable in PowerShell can be stored in a specific location, then to display a list of variables that have been created and stored in a specific directory, you can use the Get-Variable command.

d. Creates a variable with a numeric data type, written without quotation marks, for example.

PS C:\Users\Administrators>$number = 12000

e. In addition to being numeric, PowerShell variables can also hold array data types, for example.

PS C:\Users\Administrators>$array = 4,5,7

f. To see the new type in a variable, you can use the command.

PS C:\Users\Administrators>$number.GetType() . FullName

g. To measure the length or amount of array data in a variable, you can use the length option, for example as follows.

PS C:\Users\Administrators>$array.Length

h. To call the 2nd array data value in a variable, you can use the following command.

PS C:\Users\Administrator>$array[2]

i. Data values in the array that were created in the previous variable ($array) can be declared back with type integer, for example.

PS C:\Users\Administrator>[int[]] $array = (4, 5, 7)

j. If in the array variable ($array) that has been given a data value, then you insert a new data value that is different from the previous one, it will produce an error.

PS C:\Users\Administrator>$array[1] = “this is a string”

Setting PowerShell Variables

9. String Operations In PowerShell Variables

a. Concatenates two strings using the plus sign (+)

PS C:\Users\Administrators>$text1 = “Monitor”

PS C:\Users\Administrators>$text2 = “Technology”

PS C:\Users\Administrators>$text1 + $text2

b. To count the number of characters in a pre-concatenated string, you can use string functions in .NET framework.

PS C:\Users\Administrators>($text1 + $text2) . Length

c. In PowerShell, it also recognizes binary operations (same as the Linux shell) which can be used to make comparisons between two data. The following table functions of several operators.

Function Extension Operators

-eq Equal Returns true if both values are equal

-lt Less than

-le Less than or equal

-gt Great than

-ge Great than or equal

-ne Not Equals Not equal

d. Decimal data value formats can also be set in PowerShell. For example changing the value of 17.5 to 17.50.

PS C:\Users\Administrator>”{0:f2}” -f 17.5

e. In order for the decimal data type to be changed to a currency type with a distance of 15 characters from the left, you can use the following command.

PS C:\Users\Administrator>” | {0,10:C}” -f 17.5

f. You can also see the clock or running time in PowerShell with the following command.

PS C:\Users\Administrator>”{0:hh:mm}” -f (Get-Date)

10. Create Script Files

Script files are files that are used to store several PowerShell commands with the aim of being able to execute those instructions. There are four kinds of rules that describe how PowerShell executes the script, which are as follows.

* Restricted, PowerShell cannot run script files, so the user must execute instructions through interactive mode.

* AllSigned, a script file that has been defined and created by a valid user (developer) can be run on PowerShell.

* RemoteSigned, the downloaded script file must come from a legitimate (trusted) developer.

* Unrestricted, there are no special requirements to run a script shell.

a. The first step, you check the type of policy (rules) in PowerShell first with the Get-ExecutionPolicy command.

PS C:\Users\Administrator>Get-ExecutionPolicy

b. Then set the value to Unrestricted.

PS C:\Users\Administrator>Set-ExecutionPolicy Unrestricted

PS C:\Users\Administrator>Get-ExecutionPolicy

Set Policy PowerShell

c. Right click the Windows PowerShell icon – select Windows PowerShell ISE.

Windows PowerShell ISE is a GUI-based host application that makes it easy for users to create, write, run shell scripts, test, and debug these scripts. In addition, support for editing code lines, using the Tab key feature, colored code lines, and help support will make it easier for users to execute them.

d. Click the File menu – select New or press Ctrl + N to write the script as shown below.

Shell Script Code

e. Save it with the name trial.ps1 in the C:\Users\Administrator\Documents folder.

f. In the PowerShell section of the Windows PowerShell ISE bottom window, type the following command.

PS C:\Users\Administrator>cd C:\Users\Administrators\Documents

g. To execute the trial.ps1 file use the command .\trial.ps1.

h. Apart from using the .\trial.ps1 command, you can also use the invoke-expression and & instructions.


So What Is PowerShell? PowerShell is an automated framework from Microsoft, with a command line shell and scripting language integrated into the .NET framework. PowerShell also has features like Scripting, Cmdlets, Simplified, Powerful object manipulation capabilities, Extensible Interface.

________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________ ________

So many articles What is PowerShell? Here's the Complete Explanation. Look forward to other interesting articles and don't forget to share this article with your friends. Thank you…

Also, read the article about What is PPPoE on routers: how it works and its advantages. And see you in another article. Bye
Read Also :
DotyCat - Teaching is Our Passion