Vorsite Cloud Services

How to Use Powershell to Write Your Own Scripts - Introduction

Written by cloudservicesforbusiness | May 23, 2014

As Microsoft's task automation framework, Powershell is a command-line shell scripting language constructed on the .NET Framework. Programmers can easily take care of common administration tasks using both remote and local Windows operating systems. Powershell also offers full access to WMI and COM. Best of all, Powershell is its own scripting language, and has a reputation for being one of the easiest scripting languages to learn, even for users with limited coding experience.

The goal of PowerShell is to provide scripts for automation of repetitive tasks. Users can use old languages (like dos commands) before continuing to PowerShell-specific commands in built-in Aliases or new Aliases.

Features Included in Windows PowerShell

There are many features included in Windows PowerShell, however, in addition to its ability to use the .net Framework and build related objects.

  • Cmdlets (scripts) for automating common administrative tasks including using Windows Management Instrumentation, managing the registry, using event logs, and performing services.
  • Scripting language based on tasks, along with command-line tools and existing scripts.
  • Easy to share data due to a consistent design and the ability to store common naming conventions and syntax.
  • The ability to build custom tools and administer software through utilities - perfect for enterprise developers and software vendors.
  • Simple navigation of the registry and all other stores of data using the same methods of navigating the file system.

One of the best features of PowerShell is a built-in Help feature, which allows you to precede any item with "help" or end any item with "-?" to see available commands and the enormous Powershell information stores.

Your First PowerShell Command

PowerShell also allows an easy transition from .NET, UNIX, and perl.

Every PowerShell command relies on a Verb-Noun pair - commands begin with a verb, and end with a noun connected by a hyphen. As an example, "set-location" is the same command as cd (or change directory) in DOS. Some commands even automatically add the verb. You can type "childitem" and PowerShell Get-Childitem. If you're experienced with scripting, you can create your own Aliases in addition to the existing PowerShell library.

As you continue to create scripts, write them in a single text file ending in the .ps1 extension. By saving this text file to the PowerShell working directory you can execute all scripts from the Microsoft Shell.

It's rare that a scripting language allows a programmer to use old commands from previous languages, but PowerShell's Aliases allow for cd and dir from cmd.exe.