Name | Windows PowerShell |
---|---|
Logo | |
Screenshot | |
Caption | Screenshot of a sample PowerShell session |
Developer | Microsoft Corporation |
Released | |
Latest release version | 2.0 |
Latest release date | |
Operating system | Windows XPWindows Server 2003Windows VistaWindows Server 2008Windows 7Windows Server 2008 R2 |
Platform | .NET Framework |
Status | Active |
Genre | Operating system shell |
License | Proprietary software; a component of Microsoft Windows |
Website |
Name | PowerShell |
---|---|
Logo | |
Paradigm | Multi-paradigm: Imperative, pipeline, object-oriented, functional and reflective |
Year | 2006 |
Designer | Jeffrey Snover, Bruce Payette, James Truher (et al.) |
Developer | Microsoft Corporation |
Typing | Strong, safe, implicit and dynamic |
Influenced by | Ksh, Perl, C#, CL, DCL, SQL, Tcl and Tk |
Platform | .NET Framework |
Operating system | Microsoft Windows |
Windows PowerShell is Microsoft's task automation framework, consisting of a command-line shell and associated scripting language built on top of, and integrated with the .NET Framework. PowerShell provides full access to COM and WMI, enabling administrators to perform administrative tasks on both local and remote Windows systems.
In PowerShell, administrative tasks are generally performed by cmdlets (pronounced command-lets), specialized .NET classes implementing a particular operation. Sets of cmdlets may be combined together in scripts, executables (which are standalone applications), or by instantiating regular .NET classes (or WMI/COM Objects). These work by accessing data in different data stores, like the filesystem or registry, which are made available to the PowerShell runtime via Windows PowerShell providers.
Windows PowerShell also provides a hosting mechanism with which the Windows PowerShell runtime can be embedded inside other applications. These applications then leverage Windows PowerShell functionality to implement certain operations, including those exposed via the graphical interface. This capability has been utilized by Microsoft Exchange Server 2007 to expose its management functionality as PowerShell cmdlets and providers and implement the graphical management tools as PowerShell hosts which invoke the necessary cmdlets. Other Microsoft applications including Microsoft SQL Server 2008 also expose their management interface via PowerShell cmdlets. With PowerShell, graphical interface-based management applications on Windows are layered on top of Windows PowerShell. A PowerShell scripting interface for Windows products is mandated by the Common Engineering Criteria.
Windows PowerShell includes its own extensive, console-based help, similar to man pages in Unix shells via the Get-Help
cmdlet.
Version 1.0 was released in 2006 for Windows XP SP2/SP3, Windows Server 2003, and Windows Vista. For Windows Server 2008, it is included as an optional feature.
Version 2.0 is integrated with Windows 7 and Windows Server 2008 R2 and is released for Windows XP with Service Pack 3, Windows Server 2003 with Service Pack 2 and Windows Vista with Service Pack 1.
COMMAND.COM
(in installations relying on MS-DOS, including Windows 9x) and cmd.exe
(in Windows NT family operating systems). These are regular command line interpreters that support a few basic commands. For other purposes, a separate console application needs to be provided, to be invoked from these shells. They also include a scripting language (batch files), which can be used to automate various tasks. However, they cannot be used to automate all facets of GUI functionality, in part because command-line equivalents of operations exposed via the graphical interface are limited, and the scripting language is elementary and does not allow the creation of complex scripts. In Windows Server 2003, the situation was improved, but scripting support was still considered unsatisfactory.
Microsoft attempted to address some of these shortcomings by introducing the Windows Script Host in 1998 with Windows 98, and its command-line based host: cscript.exe
. It integrates with the Active Script engine and allows scripts to be written in compatible languages, such as JScript and VBScript, leveraging the APIs exposed by applications via COM. However, it too has its own deficiencies: it is not integrated with the shell, its documentation is not very accessible, and it quickly gained a reputation as a system vulnerability vector after several high-profile computer viruses exploited weaknesses in its security provisions. Different versions of Windows provided various special-purpose command line interpreters (such as netsh and WMIC) with their own command sets. None of them were integrated with the command shell; nor were they interoperable.
By 2002 Microsoft had started to develop a new approach to command line management, including a shell called Monad (aka Microsoft Shell or MSH). The shell and the ideas behind it were published in August 2002 in a white paper entitled Monad Manifesto. Monad was to be a new extensible command shell with a fresh design that would be capable of automating a full range of core administrative tasks. Microsoft first showed off Monad at the Professional Development Conference in Los Angeles in September 2003. A private beta program began a few months later which eventually led to a public beta programme.
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. Not much later, on April 25, 2006 Microsoft formally announced that Monad had been renamed Windows PowerShell, positioning it as a significant part of their management technology offerings. Release Candidate 1 of PowerShell was released at the same time. A significant aspect of both the name change and the RC was that this was now a component of Windows, and not an add-on product.
Release Candidate 2 of PowerShell version 1 was released on September 26, 2006 with final Release to the web (RTW) on November 14, 2006 and announced at TechEd Barcelona. PowerShell for earlier versions of Windows was released on January 30, 2007.
The road to PowerShell version 2 began pretty much as soon as V1 shipped. There were three community technology preview (CTP) releases that Microsoft made available to the public. The last CTP release of Windows PowerShell v2.0 was made available in December 2008.
PowerShell v2.0 was completed and released to manufacturing in August 2009, as an integral part of Windows 7 and Windows Server 2008 R2. Versions of PowerShell for Windows XP, Windows Server 2003, Windows Vista and Windows Server 2008 were released in October 2009 and are available for download for both 32-bit and 64-bit platforms.
PowerShell.exe
launches it in a separate process; if it is a cmdlet, it is executed in the PowerShell process. PowerShell also provides an interactive command line interface, wherein the commands can be entered and their output displayed. The user interface, based on the Win32 console, offers customizable tab completion but lacks syntax highlighting. PowerShell also enables the creation of aliases for cmdlets, which are textually translated by PowerShell into invocations of the original commands. PowerShell also supports both named and positional parameters for commands. In executing a cmdlet, the job of binding the argument value to the parameter is done by PowerShell itself, but, for external executables, arguments are passed via the argv (or equivalent) variable array to be parsed by the executable.
Another concept used by PowerShell is that of a pipeline. Like Unix pipelines, PowerShell pipelines are used to compose complex commands, allowing the output of one command to be passed as input to another. A pipeline is set up by piping the output of one command (or pipeline) to another command, using the |
operator. But, unlike its Unix counterpart, the PowerShell pipeline is an object pipeline; that is, the data passed between cmdlets are fully typed objects, rather than character streams. When data is piped as objects, the elements they encapsulate retain their structure and types across cmdlets, without the need for any serialization or explicit parsing of the stream, as would be the need if only character streams were shared. An object can also encapsulate certain functions that work on the contained data. These also become available to the recipient command for use. For the last cmdlet in a pipeline, PowerShell automatically pipes its output object to the Out-Default
cmdlet, which transforms the objects into a stream of format objects and then renders those to the screen.
Because all PowerShell objects are .NET objects, they share a .ToString()
method, which retrieves the text representation of the data in an object. Windows PowerShell uses this method to convert an object to text. In addition, it also allows formatting definitions to be specified, so the text representation of objects may be customized by choosing which data elements to display, and how. However, in order to maintain backwards compatibility, if an external executable is used in a pipeline, it receives a text stream representing the object, and does not integrate with the PowerShell type system.
The PowerShell Extended Type System (ETS) is based on the .NET type system, but with extended semantics (e.g. propertySets and 3rd party extensibility) . For example, it enables the creation of different views of objects by exposing only a subset of the data fields, properties, and methods, as well as specifying custom formatting and sorting behavior. These views are mapped to the original object using XML-based configuration files.
Cmdlets are specialized .NET classes, which the PowerShell runtime instantiates and invokes when they are run. Cmdlets derive either from Cmdlet
or from PSCmdlet
, the latter being used when the cmdlet needs to interact with the PowerShell runtime. These base classes specify certain methods - BeginProcessing()
,
ProcessRecord()
and EndProcessing()
- one of which the cmdlet's implementation overrides to provide the functionality. Whenever a cmdlet is run, these methods are invoked by PowerShell in sequence, with ProcessRecord()
being called if it receives pipeline input. If a collection of objects is piped, the method is invoked for each object in the collection. The class implementing the Cmdlet must have one .NET attribute - CmdletAttribute
- which specifies the verb and the noun that make up the name of the cmdlet. Common verbs are provided as an enum.
If a cmdlet receives either pipeline input or command-line parameter input, there must be a corresponding property in the class, with a mutator implementation. PowerShell invokes the mutator with the parameter value or pipeline input, which is saved by the mutator implementation in class variables. These values are then referred to by the methods which implement the functionality. Properties that map to command-line parameters are marked by ParameterAttribute
and are set before the call to BeginProcessing()
. Those which map to pipeline input are also flanked by ParameterAttribute
, but with the ValueFromPipeline
attribute parameter set.
The implementation of these cmdlet classes can refer to any .NET API and may be in any .NET language. In addition, PowerShell makes certain APIs available, such as WriteObject()
, which is used to access PowerShell-specific functionality, such as writing resultant objects to the pipeline. Cmdlets can use .NET data access APIs directly or use the PowerShell infrastructure of PowerShell Providers, which make data stores addressable using unique paths. Data stores are exposed using drive letters, and hierarchies within them, addressed as directories. Windows PowerShell ships with providers for the file system, registry, the certificate store, as well as the namespaces for command aliases, variables, and functions. Windows PowerShell also includes various cmdlets for managing various Windows systems, including the file system, or using Windows Management Instrumentation to control Windows components. Other applications can register cmdlets with PowerShell, thus allowing it to manage them, and, if they enclose any datastore (such as databases), they can add specific providers as well.
In PowerShell V2, a more portable version of Cmdlets called Modules have been added. The PowerShell V2 release notes state, "Modules allow script developers and administrators to partition and organize their Windows PowerShell code in self-contained, reusable units. Code from a module executes in its own self-contained context and does not affect the state outside of the module. Modules also enable you to define a restricted runspace environment by using a script."
While Unix/Linux systems have long employed the concept of pipelines, PowerShell differs in what is passed between stages in the pipeline. In Unix the output of one command is piped to the next stage of the pipeline typically as raw text. With PowerShell, the pipeline consists of .NET Objects. Using objects eliminates the need to parse arbitrary text output from one command to extract data since all objects export a consistent interface.
if-then-else
), loops (while
, do
, for
, and foreach
), structured error/exception handling and closures/lambda expressions, as well as integration with .NET. Variables in PowerShell scripts have names that start with $
; they can be assigned any value, including the output of cmdlets. While the language is untyped, internally the variables are stored with their types, which can be either primitive types or objects. Strings can be enclosed either in single quotes or in double quotes: when using double quotes, variables will be expanded even if they are inside the quotation marks. According to the variable syntax, if the path to a file is enclosed in braces preceded by a dollar sign (as in ${C:\foo.txt}
), it refers to the contents of the file. If it is used as an L-value, anything assigned to it will be written to the file. When used as an R-value, it will be read from the file. If an object is assigned, it is serialized before storing it.
Object members can be accessed using .
notation, as in C# syntax. PowerShell provides special variables, such as $args
, which is an array of all the command line arguments passed to a function from the command line, and $_
, which refers to the current object in the pipeline. PowerShell also provides arrays and associative arrays. The PowerShell scripting language also evaluates arithmetic expressions entered on the command line immediately, and it parses common abbreviations, such as GB, MB, and KB.
Using the function
keyword, PowerShell provides for the creation of functions, which can take parameters. A common problem for people new to PowerShell is that function arguments are separated by spaces, not commas:
#
: Calls the function with two arguments. (These arguments may be bound to parameters declared in the function definition or accessed by position from the $args array.)
#
: Calls the function with a single argument, a two element array.
PowerShell allows any .NET methods to be called by providing their namespaces enclosed in brackets ([]
), and then using a pair of colons (::
) to indicate the static method. For example,
[System.Console]::WriteLine("PowerShell")
.
Objects are created using the New-Object
cmdlet. Calling methods of .NET objects is accomplished by using the regular .
notation.
For error handling, PowerShell provides a .NET-based exception handling mechanism. In case of errors, objects containing information about the error (Exception
object) are thrown, which are caught using the trap
keyword. However, the action-or-error is configurable; in case of an error, PowerShell can be configured to silently resume execution, without trapping the exception.
Scripts written using PowerShell can be made to persist across sessions in a .ps1
file. Later, either the entire script or individual functions in the script can be used. Scripts and functions are used analogously with cmdlets, in that they can be used as commands in pipelines, and parameters can be bound to them. Pipeline objects can be passed between functions, scripts, and cmdlets seamlessly. However, script execution is disabled by default and must be enabled explicitly. PowerShell scripts can be signed to verify their integrity, and are subject to Code Access Security.
The PowerShell scripting language supports binary prefix notation similar to the scientific notation supported by many programming languages in the C-family.
Runspace
object. The state of the runspace is encased in a SessionState
object. When the runspace is created, the Windows PowerShell runtime initializes the instantiation, including initializing the providers and enumerating the cmdlets, and updates the SessionState
object accordingly. The Runspace then must be opened for either synchronous processing or asynchronous processing. After that it can be used to execute commands.
To execute a command, a pipeline (represented by a Pipeline
object) must be created and associated with the runspace. The pipeline object is then populated with the cmdlets that make up the pipeline. For sequential operations (as in a PowerShell script), a Pipeline object is created for each statement and nested inside another Pipeline object. When a pipeline is created, Windows PowerShell invokes the pipeline processor, which resolves the cmdlets into their respective assemblies (the command processor) and adds a reference to them to the pipeline, and associates them with an InputPipe
, Outputpipe
and ErrorOutputPipe
objects, to represent the connection with the pipeline. The types are verified and parameters bound using reflection. Once the pipeline is set up, the host calls the Invoke()
method to run the commands, or its asynchronous equivalent - InvokeAsync()
. If the pipeline has the Write-Host
cmdlet at the end of the pipeline, it writes the result onto the console screen. If not, the results are handed over to the host, which might either apply further processing or display it itself.
The hosting APIs are used by Microsoft Exchange Server 2007 to provide its management GUI. Each operation exposed in the GUI is mapped to a sequence of PowerShell commands (or pipelines). The host creates the pipeline and executes them. In fact, the interactive PowerShell console itself is a PowerShell host, which interprets the scripts entered at command line and creates the necessary Pipeline
objects and invokes them.
A non-exhaustive list of the new features included in PowerShell V2 is:
BeginProcessing()
, ProcessRecord()
and EndProcessing()
functions of a cmdlet are called.Out-GridView
, which displays tabular data in the WPF GridView object.-Split
, -Join
, and Splatting (@
) operators.<#
and #>
as delimiters.
!Windows PowerShell(Cmdlet) | !Windows PowerShell(Alias) | !cmd.exe / COMMAND.COM(MS-DOS, Windows, OS/2, etc.) | Bash (Unix shell)>Bash(Unix, BSD, Linux, Mac OS X etc.) | !Description |
Get-ChildItem | gci, dir, ls | ls | List all files / directories in the (current) directory | |
Get-Content | gc, type, cat | Get the content of a file | ||
Get-Command | gcm | List available commands | ||
Get-Help | help, man | Help on commands | ||
Clear-Host | cls, clear | Clear the screen | ||
Copy-Item | cpi, copy, cp | Copy one or several files / a whole directory tree | ||
Move-Item | mi, move, mv | mv | Move a file / a directory to a new location | |
Remove-Item | ri, del, erase, rmdir, rd, rm | del, erase, rmdir, rd | Delete a file / a directory | |
Rename-Item | rni, ren, mv | ren (command) | [[mv | Rename a file / a directory |
Get-Location | gl, pwd | pwd | Display the current directory/present working directory. | |
Pop-Location | popd | popd | Change the current directory to the directory most recently pushed onto the stack | |
Push-Location | pushd | pushd | Push the current directory onto the stack | |
Set-Location | sl, cd, chdir | cd (command) | cd | Change the current directory |
Tee-Object | tee | n/a | Pipe input to a file or variable, then pass the input along the pipeline | |
Write-Output | echo, write | echo | Print strings, variables etc. to standard output | |
Get-Process | gps, ps | tlist, tasklist | List all currently running processes | |
Stop-Process | spps, kill | kill | Stop a running process | |
Select-String | n/a | [[grep | Print lines matching a pattern | |
Set-Variable | sv, set | env, export, set, setenv | Set the value of a variable / create a variable |
PS> ps p* | kill
PS> ps | ? { $_.WS -gt 1000MB } | kill
PS> ls | measure length -s
PS> dir | measure length -s
PS> (ps notepad).WaitForExit()
PS> gwmi -co MyServer Win32_BIOS | select SerialNumber
Application | Version | Cmdlets | Provider | Management GUI |
2007 | ||||
Microsoft SQL Server | 2008 | |||
System Center Operations Manager | 2007 | |||
System Center Virtual Machine Manager | 2007 | |||
System Center Data Protection Manager | 2007 | |||
Windows Compute Cluster Server | 2007 | |||
08.02.0012 | ||||
1.0 | ||||
IBM WebSphere MQ | 6.0.2.2 | |||
1.1 | ||||
Special Operations Software Specops Command | 1.0 | |||
1.5 | ||||
Internet Information Services | 7.0 | |||
Windows 7 Troubleshooting Center | 6.1 | |||
Microsoft Deployment Toolkit | 2010 | |||
NetApp Data ONTAP PowerShell Toolkit | 1.5 | |||
JAMS Scheduler - Job Access & Management System | 5.0 |
Category:.NET programming languages Category:Dynamically typed programming languages Category:Interpreters (computing) Category:Windows administration Category:Object-oriented programming languages Category:Procedural programming languages Category:Scripting languages Category:Text-oriented programming languages Category:Command shells
ar:ويندوز باورشيل ca:Windows PowerShell cs:Windows PowerShell de:Windows PowerShell es:Windows PowerShell fa:ویندوز پاورشل fr:Windows PowerShell ko:윈도 파워셸 id:Windows PowerShell it:Windows PowerShell nl:Windows PowerShell ja:Windows PowerShell pl:Windows PowerShell pt:Windows PowerShell ru:Windows PowerShell fi:Windows PowerShell tr:Windows PowerShell uk:Windows PowerShell yi:Windows PowerShell zh:Windows PowerShellThis text is licensed under the Creative Commons CC-BY-SA License. This text was originally published on Wikipedia and was developed by the Wikipedia community.
The World News (WN) Network, has created this privacy statement in order to demonstrate our firm commitment to user privacy. The following discloses our information gathering and dissemination practices for wn.com, as well as e-mail newsletters.
We do not collect personally identifiable information about you, except when you provide it to us. For example, if you submit an inquiry to us or sign up for our newsletter, you may be asked to provide certain information such as your contact details (name, e-mail address, mailing address, etc.).
When you submit your personally identifiable information through wn.com, you are giving your consent to the collection, use and disclosure of your personal information as set forth in this Privacy Policy. If you would prefer that we not collect any personally identifiable information from you, please do not provide us with any such information. We will not sell or rent your personally identifiable information to third parties without your consent, except as otherwise disclosed in this Privacy Policy.
Except as otherwise disclosed in this Privacy Policy, we will use the information you provide us only for the purpose of responding to your inquiry or in connection with the service for which you provided such information. We may forward your contact information and inquiry to our affiliates and other divisions of our company that we feel can best address your inquiry or provide you with the requested service. We may also use the information you provide in aggregate form for internal business purposes, such as generating statistics and developing marketing plans. We may share or transfer such non-personally identifiable information with or to our affiliates, licensees, agents and partners.
We may retain other companies and individuals to perform functions on our behalf. Such third parties may be provided with access to personally identifiable information needed to perform their functions, but may not use such information for any other purpose.
In addition, we may disclose any information, including personally identifiable information, we deem necessary, in our sole discretion, to comply with any applicable law, regulation, legal proceeding or governmental request.
We do not want you to receive unwanted e-mail from us. We try to make it easy to opt-out of any service you have asked to receive. If you sign-up to our e-mail newsletters we do not sell, exchange or give your e-mail address to a third party.
E-mail addresses are collected via the wn.com web site. Users have to physically opt-in to receive the wn.com newsletter and a verification e-mail is sent. wn.com is clearly and conspicuously named at the point of
collection.If you no longer wish to receive our newsletter and promotional communications, you may opt-out of receiving them by following the instructions included in each newsletter or communication or by e-mailing us at michaelw(at)wn.com
The security of your personal information is important to us. We follow generally accepted industry standards to protect the personal information submitted to us, both during registration and once we receive it. No method of transmission over the Internet, or method of electronic storage, is 100 percent secure, however. Therefore, though we strive to use commercially acceptable means to protect your personal information, we cannot guarantee its absolute security.
If we decide to change our e-mail practices, we will post those changes to this privacy statement, the homepage, and other places we think appropriate so that you are aware of what information we collect, how we use it, and under what circumstances, if any, we disclose it.
If we make material changes to our e-mail practices, we will notify you here, by e-mail, and by means of a notice on our home page.
The advertising banners and other forms of advertising appearing on this Web site are sometimes delivered to you, on our behalf, by a third party. In the course of serving advertisements to this site, the third party may place or recognize a unique cookie on your browser. For more information on cookies, you can visit www.cookiecentral.com.
As we continue to develop our business, we might sell certain aspects of our entities or assets. In such transactions, user information, including personally identifiable information, generally is one of the transferred business assets, and by submitting your personal information on Wn.com you agree that your data may be transferred to such parties in these circumstances.