WINDOWS POWERSHELL


'Windows PowerShell', previously 'Microsoft Shell' or 'MSH' (codenamed 'Monad') is an extensible command line interface (CLI) shell and scripting language product developed by Microsoft. The product is based on object-oriented programming and version 2.0 of the Microsoft .NET Framework. It is available for Windows XP, Windows Server 2003 and Windows Vista and planned for inclusion with Windows Server 2008.[1]
Windows PowerShell is the foundation of the administrative tools for Exchange Server 2007, System Center Virtual Machine Manager 2007 and System Center Operations Manager 2007 where everything is done via command line interfaces and the administrative GUI is layered on top of those commands.

Contents
History
Central concepts
Features
Cmdlets
Examples
File extensions
List of Microsoft projects using PowerShell
See also
References
Books
External links
Official Websites
Windows PowerShell Team
3rd Party Tools
Users Groups and Communities
Tutorial

History


Every released version of Microsoft DOS and Microsoft Windows for personal computers has featured a command line interface tool. These have been COMMAND.COM (in installations relying on MS-DOS) and cmd.exe (in Windows NT-based installations). These were not always capable of reproducing or automating all of the administrative functions available in the graphical user interface (GUI). This has been due to limitations within the command-line equivalents or to Microsoft not providing full fidelity command-line equivalents, although under Windows Server 2003, this situation was improved. Users have also been hindered by a lack of adequate documentation of command-line functionality.
Microsoft attempted to address some of these shortcomings by introducing the Windows Script Host in 1998 with Windows 98. The Windows Script Host was a new scripting layer which could implement a variety of scripting languages. However, the Script Host had its own deficiencies. It was not integrated with the shell, its documentation was not very accessible, and it quickly gained a reputation as a system vulnerability after several high-profile computer viruses exploited substantial weaknesses in its security provisions.
Windows Server 2003 and certain versions of Windows XP included a command-line-based script host called CScript.exe (essentially just a portion of the Windows Script Host introduced earlier), but it was not integrated into the existing shell (cmd.exe). These operating systems provided other ''ad hoc'' CLIs as well (netsh, for example), which were not fully integrated either.
By 2003 Microsoft had started to develop a new shell called Monad (aka MSH), a new extensible command shell with a fresh design which would be capable of automating a full range of core administrative tasks.
Microsoft published the first Monad public beta release on June 17 2005, Beta 2 on September 11 2005 and Beta 3 on January 10 2006.
Microsoft announced on April 25 2006 that Monad was renamed to Windows PowerShell, positioning it as a significant part of their management technology offerings.[2] Release Candidate 1 of PowerShell was released at the same time.
Release Candidate 2 of PowerShell was released September 26 2006.
Windows PowerShell v1.0 was released to web (RTW) November 14 2006.
PowerShell for Vista was released on January 30 2007.[3]
Microsoft has committed to building future GUI tools on top of PowerShell, ensuring that the core administrative functionality remains scriptable. Exchange Server 2007's management user interface, for example, is built on top of PowerShell. In most everyday tasks, PowerShell can be used in place of CMD.EXE and Windows Script Host (WSH). However, for backward-compatibility purposes both CMD.EXE and WSH will continue to be supported by Windows.

Central concepts


PowerShell's codename, which is ''Monad'', alludes to Gottfried Leibniz's monadology,[4] a philosophy in which the universe is a composite of fundamental elements (''monads'') that are integrated in a "pre-established harmony." Similarly, PowerShell is a composite of the complex tasks of a series of components. These components are special programs dubbed ''cmdlets'' (pronounced "command-lets"), which are .NET classes designed to use the features of the environment. PowerShell's main distinction from standard UNIX shells is that, rather than creating a pipeline based on ''text'' streams, PowerShell cmdlets pass data as ''objects''.
If invoked individually from the command line, a cmdlet's output is converted automatically into text, but if its output is to be used by another cmdlet, it is converted into the appropriate object type for the receiving cmdlet. This eliminates much need for the many text-processing utilities that are common in UNIX pipelines, such as grep and awk, and allows things to be combined interactively (or in a scripting environment) without pressuring for the usage of a more complex programming language. For instance: a listing of processes internally consists not of text describing the processes, but of objects representing them, so that methods can be called on those objects without explicit reference to any outside structure or library.

Features


The first version contains the following features:

★ A C#-like scripting language with support for hash tables, switch statements which can test on regular expressions, array slicing and anonymous methods (script blocks) which can be stored as data and then later executed. It also provides looping (for/foreach/while), conditional statements (if/switch), variable scoping (global/script/local) and the ability to define functions.

★ Cmdlets inherit certain options, allowing the user to choose things such as the level of interaction and how to deal with errors. Cmdlets which produce side effects support the options -WhatIf and -Confirm. -WhatIf informs the user what would have happened, but no action takes place. -Confirm informs the user what is about to happen and allows the user to control whether it takes place or not.

★ One option for dealing with errors is to invoke a "suspend" feature which allows the user to enter a new command shell, investigate a problem, and resume the original command (also available in the Bourne shell (sh) and bash). The user can define the prompts to be shown in such circumstances.

★ An extensible ''provider'' model allows access to and manipulation of the file system and other hierarchical data stores. Some examples: PowerShell comes with a registry provider which allows access to the registry via the "HKLM" and "HKCU" hives; with this, the registry can be browsed by executing commands like dir HKLM:SOFTWAREMicrosoft at the shell prompt. PowerShell comes with providers for the certificate store, the environment, and shell functions and aliases. Like cmdlets, the provider model is extensible, allowing third parties to create their own provider model and plug it into PowerShell.

★ A concept called "execution policies" which allows coarse security constraints to be imposed upon PowerShell script execution. Execution policies define the restrictions under which PowerShell loads configuration files and runs scripts. The four execution policies are Restricted, AllSigned, RemoteSigned, and Unrestricted.

★ Support for the use of script signing to verify the identity of a script publisher and to validate the integrity of a published script using digital signatures.

★ The command-line options are generally whole words, but can be specified as the minimum number of letters necessary to disambiguate. For example, the option -show-detailed-information could be entered as -s if no other option begins with 's'.

★ Comprehensive, user-extensible tab completion features. The cmd.exe shell in current versions of Windows can only complete file or directory names, in contrast to the advanced completion in shells such as bash and zsh.

★ The ability to assign the output of a command to a variable, which will then be an object or array of objects inspectable in any way desired.

Cmdlets


The following table contains a selection of the more than 129 Cmdlets that ship with PowerShell as well as the equivalent commands in other command line interpreters.
Windows PowerShell
(Cmdlet)
Windows PowerShell
(Alias)
cmd.exe / COMMAND.COM
(MS-DOS, Windows, OS/2, etc.)
bash
(Unix, BSD, Linux, etc.)
Description
Set-Locationsl, cd, chdircd, chdircdChange the current directory
Clear-Hostcls, clearclsclearClear the screen
Copy-Itemcpi, copy, cpcopycpCopy one or several files / a whole directory tree
Get-Helphelp, manhelpmanHelp on commands
Remove-Itemri, del, rmdir, rd, rmdel, rmdir, rdrm, rmdirDelete a file / a directory
Rename-Itemrni, renrenmvRename a file / a directory
Get-ChildItemgci, dir, lsdirlsList all files / directories in the (current) directory
Write-Outputecho, writeechoechoPrint strings, variables etc. to screen
Pop-LocationpopdpopdpopdChange the current directory to the directory most recently pushed onto the stack
Push-LocationpushdpushdpushdPush the current directory onto the stack
Set-Variablesv, setsetsetSet the value of a variable / create a variable
Get-Contentgc, type, cattypecatGet the content of a file
Get-Processgps, pstlist[5], tasklist[6]psList all currently running processes
Stop-Processspps, killkill[5], taskkill[6]killStop a running process

Examples



★ Stop all processes that begin with the letter "p":
PS> get-process p
★ | stop-process

★ Find the processes that use more than 1000 MB of memory and kill them:
PS> get-process | where { $_.WS -gt 1000MB } | stop-process

★ Calculate the number of bytes in the files in a directory:
PS> get-childitem | measure-object -property length -sum

★ Determine whether a specific process is no longer running:
PS> $processToWatch = get-process notepad
PS> $processToWatch.WaitForExit()

★ Change the case of a string from lower to upper:
PS> "hello, world!".ToUpper()

★ Insert the string "ABC" after the first character in the word "string" to have the result "sABCtring":
PS> "string".Insert(1, "ABC")

★ Download a specific RSS feed and show the titles of the 8 most recent entries:
PS> $rssUrl = "http://blogs.msdn.com/powershell/rss.aspx"
PS> $blog = [xml](new-object System.Net.WebClient).DownloadString($rssUrl)
PS> $blog.rss.channel.item | select title -first 8

★ Sets $UserProfile to the value of the UserProfile environment variable
PS> $UserProfile = $env:UserProfile

File extensions



★ PS1 - Windows PowerShell shell script

★ PS1XML - Windows PowerShell format and type definitions

★ PSC1 - Windows PowerShell console file

List of Microsoft projects using PowerShell



★ Exchange 2007

★ System Center Operations Manager 2007 (SCOM 2007)

★ System Center Virtual Machine Manager 2007 (VMM)

★ System Center Data Protection Manager 2007 (DPM)

★ Microsoft Transporter Suite for Lotus Domino

★ Windows Compute Cluster Tool Pack

★ Windows Server 2008

See also



Comparison of computer shells

References


1. Windows Server 2008: Windows PowerShell: Now Part of Windows Server 2008 Beta 3
2. Windows PowerShell (Monad) Has Arrived
3. Windows PowerShell : Windows PowerShell & Windows Vista
4. Monad Manifesto – the Origin of Windows PowerShell
5. Available in Windows NT4, Windows 98 Resource Kit, Windows 2000 Support Tools
6. Available in Windows XP Professional Edition and later
7. Available in Windows NT4, Windows 98 Resource Kit, Windows 2000 Support Tools
8. Available in Windows XP Professional Edition and later

Books


Windows PowerShell in Action, , Bruce, Payette, , , ISBN 1-932394-90-7

Professional Windows Powershell Programming: Snapins, Cmdlets, Hosts and Providers, , Arul, Kumaravel, , , ISBN 0470173939

Monad - Introducing the MSH Command Shell and Language (the ''Toad book'', , Andy, Oakley, , , ISBN 0-596-10009-4

An Introduction to Microsoft® PowerShell™, , Don, Jones, , ,

Windows PowerShell™: TFM®, , Don, Jones, , , ISBN 0-9776597-1-2

Windows PowerShell Quick Reference, , Lee, Holmes, , , ISBN 0-596-52813-2

Windows PowerShell: The Definitive Guide: Rough Cuts Version, , Lee, Holmes, , , ISBN 0-596-51432-8

Microsoft Windows Powershell Programming for the Absolute Beginner, , Jerry Lee, Ford Jr, , , ISBN 1-59863-354-6

Professional Windows PowerShell, , Andrew, Watt, , , ISBN 0-471-94693-1

Microsoft Powershell Unleashed, , Tyson, Kopczynski, , , ISBN 0672329530

Microsoft® Windows PowerShell™ Step By Step, , Ed, Wilson, , , ISBN 0-7356-2395-3

External links


Official Websites


PowerShell homepage

How to Download Windows PowerShell 1.0

Scripting with Windows PowerShell

How Windows PowerShell Works

''Monad: The Future of Windows Scripting'' - an article in TechNet Magazine by Thomas Lee.
Windows PowerShell Team


Windows PowerShell Team Blog

Channel9 Interviews/Demos with Jeffrey Snover - the Architect of Windows PowerShell

Port25.TechNet.com Interview with Bruce Payette - one of the founders of the Powershell team and co-designer of the PowerShell language

TechNet Script Center Interview with Jeffrey Snover - the Architect of Windows PowerShell

''Windows PowerShell and the “PowerShell Worm”'' - an analysis, by Leonard Chung of the Windows PowerShell Team, of the "PowerShell Worm" and a walkthrough of Windows PowerShell's security features and how they strongly reduce the risk of scripting malware.

''Monad and the "First Vista Virus" - a clarification by Lee Holmes, a developer on the Windows PowerShell Team
3rd Party Tools


Admin Script Editor IDE - Commercial script editor with support for PowerShell and VBScript.

Powershell.com - Powershell IDE and editor tools.

PrimalScript - Example of a commercial Windows PowerShell editing environment

PowerGUI Community - PowerGUI is an extensible graphical administrative console for managing systems based on Windows PowerShell.

PowerShell Remoting - a light-weighted server-client application to connect to remote PowerShell host and run script interactively.

PowerGadgets - Desktop reporting and monitoring for IT/DB professionals.
Users Groups and Communities


Powershell Live - Powershell Live - The Powershell User community with forums, chat, articles, blogs, editorial columns, downloads and the latest Powershell News.

Get-PSUGUK - UK PowerShell Users Group

PowerScripting Podcast - PowerScripting Podcast - A podcast for people learning Windows PowerShell with segments covering cmdlets, tips, resources, gotchas etc
Tutorial


Ars Technica - A guided tour of the Microsoft Command Shell

Mastering PowerShell in your Lunch Break - a step by step introduction to powershell by Dr Tobias Weltner ( Powershell MVP)

This article provided by Wikipedia. To edit the contents of this article, click here for original source.

psst.. try this: add to faves