realLifeinfo

A briefly introduction to Microsoft Windows PowerShell console

Nerd, Solutions 

PowerShell is the new shell for Microsoft windows operating systems, this shell appeared first in Microsoft Windows 7. The name of this shell was derived from the fact that this is the shell environment and a powerfully one for windows system administrators. As a window system administrator you can perform any task from windows PowerShell console, those task can range from process and service management, user creation, network adapter management and other administration tasks.

Sponsored

Briefly introduction to Windows PowerShell

Windows PowerShell comes comes in two flavors; The first one is Windows PowerShell Interactive Console. This console is similar to KORN or BASH in UNIX Eco-system. This interactive console is built on top of windows command prompt.

The second flavor of windows PowerShell is the PowerShell ISE. This is the integrated scripting environment designed for script writing. But, this environment is not limited only for script writing and it can be used as PowerShell interactive console to execute commands. In fact, many windows PowerShell users prefer PowerShell ISE over PowerShell interactive console, because this environment support syntax coloring, drop-down lists, and automatic parameter revelation features.

Each flavor of windows PowerShell can be started as an administrator or a normal non-elevated user. The best practice is to start windows PowerShell with a minimum rights as possible to achieve your intended goals.

Introduction to Windows PowerShell cmdlets

Commands that are executed by windows PowerShell console are known as PowerShell cmdets. All windows PowerShell cmdlets are composed of two parts; the first part is the verb part and the second part is the noun part. The verb and noun part are not always grammatical correct. Example of the verbs are: get, set, add, remove and format. Noun part is the thing to which the action will apply like process, services, user and other.

The Get Verb:

Get is the most common PowerShell verb, around 25% of all windows PowerShell functions and cmdlets use the get verb, and they are more than 2000 cmdlets and functions combined. The get verb retrieve information and the noun part describes which information to retrieve information about all running process in the system Get-process.

Example of PowerShell get verb cmdlets:

You can use the get Verb to retrieve any desired information from the system. All you have to do is just provide the Noun you want to query.

PowerShell cmdlets parameters

Sponsored

Many PowerShell cmdlets can be used without passing any parameters, but this does not mean you can't use parameters with cmdlets. When working with windows PowerShell cmdlets, often the cmdlet requires only a single parameter to filter out the results. If a parameter is the default parameter, you do not have to specify the parameter name; you can use the parameter position. This means that the first value appearing after the cmdlet name is assumed to be a value of the default.

Use parameter to find specific running process

We can use get-process cmdlet to retrieve information about all process that are currently running in the system. But, when you want information for one specific process you can use get-process with the -name parameter. Syntax: get-process -name process_name.

Example: get-process -name chrome. This command will retrieve only information about the process named chrome. This command can be written like this: get-process chrome, because -name parameter is the default parameter for get-process cmdlet.

Another example of using cmdlet with parameters is when we want to generate random number within a certain range. This is achieved by using get-random cmdlet and -maximum and -minimum parameters.

Example: get-random; aline this cmdlet will generate random number and output it into the console. To generate random number within 0 and 10 we provide -maximum and -minimum parameters to get-random cmdlet.

This command will generate and display only number between 0 and 10.

Execute command prompt commands

In windows PowerShell console you can execute normal command prompt commands, like to view IP address information in the system using command prompt approach, we execute ipconfig command. Also the same information can be retrieved in windows PowerShell approach by executing get-NetIPAddress cmdlet. As you can see we can use either approach to achieve the same outcome, but they are several advantages in using PowerShell approach. One of the advantage is because command prompt approach returns plain text to the console, but PowerShell approach returns an object. This means you can group, sort, filter, and format the output in an easy way.

View how to use cmdlet

You can view how to use a certain cmdlet by executing get-help or help cmdlet followed by the name of the cmdlet you want to use. Example, to view information on how to use the get-process cmdlet we  type this command into the console: get-help get-process.

Note: Not all help information about cmdlets are by default installed in your system, you will need to update the local copy of the help information. This can be achieved by update-help cmdlet.

Sponsored