Basic introduction to PowerShell

Spread the words

What is PowerShell ?

PowerShell is an automation platform and scripting language for Windows and Windows Server that allows you to simplify the management of your systems. Unlike other text based shells, PowerShell harnesses the power of the .NET Framework, providing rich objects and a massive set of built in functionality for taking control of your Windows environments.

Windows Management Framework (WMF) contains the latest versions of PowerShell.

PowerShell MSDN site:

What PowerShell is capable of?

  • PowerShell works with standard Windows commands and applications.
  • PowerShell commands (called cmdlets) share a common verb-noun syntax.
  • PowerShell understands objects.
  • PowerShell focuses strongly on its use as an interactive shell.
  • PowerShell supports discovery.
  • PowerShell enables ubiquitous scripting.
  • PowerShell bridges many technologies. By letting you work with .NET, COM, WMI, XML and Active Directory.
  • PowerShell simplifies management of data stores.

To start Windows PowerShell, do one of the following:

Click start->All Programs->Accessories->Windows PowerShell.

Click start->Run, and then type PowerShell.

Once you’ve started the PowerShell prompt, you can enter DOS style and Unix style commands to navigate around the filesystem.

start ps

Here is an example:

Pushd (push-location) stores the name of the current directory for use by the popd (pop-location) command before changing the current directory to the specified directory.

Cd (change directory) changes the current working directory.

Dir displays a list of a directory’s files and subdirectories.

Pwd (print working directory) writes the full pathname of the current working directory.


In the following example we’re deleting txt files from the c:\old folder and then back to the current location. This could be an interesting option when you create scripts.


You can also run the usual Windows tools like ipconfig, notepad and more with PowerShell.

Structured Commands (CMdlets):

PowerShell introduces a powerfull new type of command called a cmdlet (pronounced command-let). All cmdlets are named in a verb noun pattern, such as Get-Process, Get-Content, and Stop-Process.


PowerShell lets you use the Tab key to autocomplete cmdlet names and parameter names.

PS > Get –Pr<TAB> -N<TAB> lsass

PowerShell defines aliases for all common commands and lets you define your own. PowerShell also permits parameter shortening.


Powershell supports positional parameters on cmdlets. Positional parameters let you provide parameter values in a certain position on the command line, rather than having to specify them by name.


Deep integration of Objects:

The following command generates a simple text string. Since nothing captures that output, PowerShell displays it to you.


For example, to access the Length property of the string Hello World, you place a dot between the object and its property name.


All PowerShell commands that produce output generate that output as objects as well, which you can store in a variable. In PowerShell, variable names start with a $ character. The following command stores the Notepad process.


Now you can use Kill() to stop the notepad process as follow.


Some fun examples:

How many disks will it take to back up a 40 GB hard drive to CD-ROM?


Is 2008 a leap year?


How much time remains until next summer?


Composable commands:

Whenever a command generates output, you can use a pipeline character (|) to pass that output directly to another command as input. You can chain together many commands this way. The following command gets all items in folder1 directory and moves them to the folder2 directory.


In the following example, the first command gets all processes on the system. It passes those to the Where-Object cmdlet that runs a comparison. The comparison is $_.Handles –ge 500, which checks whether the Handles property of the processes is greater than or equal to 500. It passes the results to the Sort-Object cmdlet, asking to sort by their Handles property. Then, it passes the results to the Format-Table cmdlet to generate a table of the processes.


Auto Protection:

PowerShell supports – WhatIF and – Confirm parameters that let you see what a command would do. The following command used with – WhatIF show what the command do without executing it for real.



The Get-Command cmdlet list the available Powershell commands.


By entering the following, you can find out which PowerShell commands contain the word process.


To see what a command such as Get-Process does, use the Get-Help cmdlet, as follow.


Ubiquitous Scripting:

PowerShell makes no distinction between the commands typed at the command line and the commands written in a script. The following example add up the handle count for all running processes.


Ad Hoc Development:

Retrieve the history of a session and send the output to a new script file.


Bridging Technologies:

PowerShell fully works with .NET Framework and it works also with

  • XML
  • Windows Management Instrumentation (WMI) and CIM


  • Active Directory Service Interfaces (ADSI)


  • COM Objects


Namespace Navigation using Providers:

Navigating the filesystem


Navigating the registry


Navigating the certificate store


Folks, that’s all for a basic introduction to PowerShell.

Leave a comment

Your email address will not be published.