Skip to main content

Command Prompt and Windows PowerShell – The Basics

By April 27, 2015September 9th, 2020Blog, Microsoft

Windows PowerShell is a task-based command-line shell and scripting language designed especially for system administration. It is built on the .NET Framework and helps IT professionals and power users control and automate the administration of the Windows operating systems. PowerShell was designed to automate system tasks, such as batch processing, and create systems management tools for commonly implemented processes.

Most of the commands are done in a scripting language called Cmdlets, which is ultimately are the heart-and-soul of Windows PowerShell. Over a hundred cmdlets are included that can be used separately or combined with others to automate more complex tasks. Users can also create and share cmdlets. PowerShell also includes a plethora of standard command line tools for functions that formerly required users to create scripts in C# (C-Sharp).

PowerShell is available as a free (YAY!) download for Windows XP, Server 2003 and Vista (EW!). Support for PowerShell is built into Windows Server 2008 and Win 7 but only as an additionally installed feature.

Some really cool Windows PowerShell features are:

  • Cmdlets for performing common system administration tasks, such as managing the registry, services, processes, and event logs
  • A task-based scripting language and support for existing scripts and command-line tools.
  • Consistent design. Because cmdlets and system data stores use common syntax and naming conventions, data can be shared easily and the output from one cmdlet can be used as the input to another cmdlet without reformatting or manipulation.

Below is a chart of some very basic cmdlets you may end up using in PowerShell

Cmdlet Function
 Get-Location  get the current directory
 Set-Location  change the current directory
Copy-Item  copy files
 Remove-Item  remove a file or directory
 Move-Item  move a file
 Rename-Item  rename a file
 New-Item  create a new empty file or directory

 

If you’re anything like me… PowerShell can be a little intimidating and if you’re concerned about remembering all the different cmdlets… fret not! Get-Command is here to save the day! Just type Get-Command without any additional parameters and you’ll get back a list of all the Windows PowerShell cmdlets! Just know that once you get your head around the logic, you’re golden.

A few tips to help you survive PowerShell as a beginner:

Write functions, not scripts – this is for reusability for both yourself and others in your team.

  • Get-help -examples is your friend! You can see a lot of useful informations about piping inputs in these examples
  • Whatif could potentially save you from making a mistake… It allows you to essentially make a dry-run of your script, without actually making any modifications (it is only valid on cmdlets that make modifications; supplying it to a get-* cmdlet will give an error.)
  • The Tab key is also incredibly useful for PowerShell. If you have an object, just add a period and Tab it out to see if there is anything there that works for you. Additionally, you could type a partial command and Tab to complete it or see other commands that match the desired pattern.
  • For parameters, hit dash and tab through the available parameters until you find the one you want

At this point, you may be thinking… I already know how to use Command Line… why should I bother with PowerShell and what are the differences?! Let’s discuss a few:

CL tool vs. PS cmdlet:

  • PowerShell as an improved and more powerful command prompt for Windows, that extends its scripting and system administration capabilities.
  • There are a lot more commands available to a PowerShell user than to a Command Line user
  • The relative simplicity of CMD makes it easier to learn and use, however, PowerShell has more goodies to play around with
  • Code organization – The CL tool addresses multiple commands and keeps similar functionality (command line parsing, processing, etc.) together. PowerShell uses one cmdlet per command and keeps the command related stuff together. While there is no real technical advantage to either, it’s just different approaches and depends on which you prefer.
  • Pipeline support – the cmdlets play top league here… and Command Line can’t compete. PowerShell provides a clean and flexible output formatting and object oriented pipelining.
  • Help support- While the CL help is quite simple, Cmdlet help aims to answer more complex needs such as addressing unclear demands. Depending on what you’re doing, it’s a toss up to your preference.

Last two bits of advice:

Google is your friend and always take calculated risks! Happy PowerShell-ing!

Alisha Khan, PEI

Leave a Reply