Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - An Introduction to Microsoft PowerShell
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

An Introduction to Microsoft PowerShell
By: Nilpo/Developer Shed Staff Writer
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2007-03-12

    Table of Contents:
  • An Introduction to Microsoft PowerShell
  • PowerShell Features
  • A Look at Cmdlets
  • Harnessing the Power

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    An Introduction to Microsoft PowerShell - A Look at Cmdlets


    (Page 3 of 4 )

    So, “what the fruit is a cmdlet?” you ask.  A cmdlet (pronounced command-let) is basically a miniature program that can be compared to an application’s dll file.  It is executable, but only within the PowerShell environment.  Cmdlets are created as PowerShell scripts.

    As I’ve stated you call specific methods in cmdlets by supplying a verb.  There are over 50 verbs, but only a few perform the most common tasks.  They are as follows:

     

    • Add (Add-content, works like append)
    • Clear (Clear-variable)
    • Expand
    • Export
    • Format (Format-list or format-table)
    • Get (Default verb, not always necessary, often assumed)
    • Group (Group-object often abbreviated to plain group)
    • Import
    • Measure (Measure-object)
    • Move
    • New (New-object, opens up a whole world of com or net objects)
    • Out (Out-file, also out-printer, even out-host)
    • Pop
    • Push
    • Read (Read-host is a method of obtaining console input)
    • Remove * (Remove-item.  PowerShell's way of deleting)
    • Resume (Service)
    • Restart (Service)
    • Set (Set-location, like cmd's cd)
    • Sort (Strictly speaking sort-object)
    • Start (Start-service)
    • Stop (Stop-service)
    • Write (Write-host, also write-output)

     

    Constructing a command is as simple as choosing a verb and a noun.  Here are some of most commonly used nouns in PowerShell:

     

    • Acl  (get-acl)
    • Alias
    • Childitem (get-childitem has an Alias of dir)
    • Command (get-command)
    • Content (get-content, has an Alias of type)
    • Drives
    • Env
    • Eventlog
    • File (Out-file)
    • Item (get-item d:scripts)
    • Process
    • Property (Get-property c:boot.ini)
    • Provider
    • Service
    • WmiObject

     

    Obviously not all of the verbs will work with all of the nouns, but it’s very simple to try them and see which ones do.  Of course, as I stated, PowerShell has a very extensive help system that lists all of the native objects including their verb-noun pairs.

    Try opening a PowerShell window and trying the Get-EventLog pair.  You will be asked to supply the name of the Event Log you’d like to view.  Just type System and press return.  Alternatively you can supply it in the original command line by typing Get-EventLog System.  You should see a return that looks something like the following.

    Index Time          Type Source                EventID Message                                                        

    ----- ----          ---- ------                ------- -------                                                         

    10439 Feb 25 19:31  Warn Tcpip                    4226 TCP/IP has reac…

    10438 Feb 25 19:04  Warn Tcpip                    4226 TCP/IP has reac…

    10437 Feb 25 18:56  Info Service Control M...     7036 The LiveUpdate…

    10436 Feb 25 18:55  Info Service Control M...     7036 The LiveUpdate…

    10435 Feb 25 18:55  Info Service Control M...     7035 The LiveUpdate…

    10434 Feb 25 18:54  Info Service Control M...     7036 The LiveUpdate…

    10433 Feb 25 18:54  Info Service Control M...     7036 The LiveUpdate…

    10432 Feb 25 18:54  Info Service Control M...     7035 The LiveUpdate…

    10431 Feb 25 18:51  Info Service Control M...     7036 The WMI Perform…

    10430 Feb 25 18:51  Info Service Control M...     7035 The WMI Perform…

    10429 Feb 25 18:51  Info Service Control M...     7036 The WMI Perform…

    10428 Feb 25 18:51  Info Service Control M...     7036 The LiveUpdate…

    10427 Feb 25 18:51  Info Service Control M...     7036 The WMI Perform…

    10426 Feb 25 18:51  Info Service Control M...     7035 The WMI Perform…

    10425 Feb 25 18:51  Info Service Control M...     7036 The WMI Perform…

    10424 Feb 25 18:51  Info Service Control M...     7036 The Application…

    If that’s too hard for you to read, then you should try pipelining.  Support for pipelining is very strong.  The command we want is Get-EventLog System | Format-List.  The Format-List cmdlet is used to control the output of the Get-EventLog cmdlet.  The output should look similar to the following:

    Index              : 10439

    EntryType          : Warning

    EventID            : 4226

    Message            : TCP/IP has reached the security limit imposed on the number of concurrent TCP connect attempts.

    Category           : (0)

    CategoryNumber     : 0

    ReplacementStrings : {}

    Source             : Tcpip

    TimeGenerated      : 2/25/2007 7:31:14 PM

    TimeWritten        : 2/25/2007 7:31:14 PM

    UserName           :

     

    Index              : 10438

    EntryType          : Warning

    EventID            : 4226

    Message            : TCP/IP has reached the security limit imposed on the number of concurrent TCP connect attempts.

    Category           : (0)

    CategoryNumber     : 0

    ReplacementStrings : {}

    Source             : Tcpip

    TimeGenerated      : 2/25/2007 7:04:44 PM

    TimeWritten        : 2/25/2007 7:04:44 PM

    UserName           :

     

    Index              : 10437

    EntryType          : Information

    EventID            : 7036

    Message            : The LiveUpdate service entered the stopped state.

    Category           : (0)

    CategoryNumber     : 0

    ReplacementStrings : {LiveUpdate, stopped}

    Source             : Service Control Manager

    TimeGenerated      : 2/25/2007 6:56:29 PM

    TimeWritten        : 2/25/2007 6:56:29 PM

    UserName           :

    More Windows Scripting Articles
    More By Nilpo/Developer Shed Staff Writer


       · You've heard all of the buzz around Microsoft's latest scripting technology. Now we...
       · Nice introduction, but the last example does not work:It was:Get Process |...
       · Thanks so much for catching that typo. I've fixed it. I'm glad you enjoyed the...
     

    WINDOWS SCRIPTING ARTICLES

    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH
    - Advanced Word Object Scripting
    - Reading and Printing Word Documents in WSH
    - Scripting Microsoft Word
    - Using WSH to Catalog MP3 Files
    - Reading MP3 ID3 Tags in WSH
    - A Brief Look at Menus in WPF
    - More Examples of Simplified Image Processing...
    - Completing a WPF To-Do List Application
    - Simplified Image Processing in GDI+





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT