Jump to content

PowerShell: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
histmerge complete. restore latest revision
Line 1: Line 1:
{{Infobox Software
{{Infobox Software
| name = Windows PowerShell
| name = Windows PowerShell
| logo = [[:Image:Windows PowerShell icon.png|64px]]
| logo = [[Image:Windows PowerShell icon.png|64px]]
| screenshot = [[:Image:PowerShell.PNG|225px]]
| screenshot = [[Image:PSshot.png|225px]]
| caption = Screenshot of a sample PowerShell session
| caption = Screenshot of a sample PowerShell session
| developer = [[Microsoft|Microsoft Corporation]]
| developer = [[Microsoft|Microsoft Corporation]]
| released = [[November 14]], [[2006]]
| latest_release_version = 1.0
| latest_release_version = 1.0
| latest_release_date = [[November 14]], [[2006]]
| latest_release_date = {{release date|2006|11|14}}
| latest preview_version = 2.0 [[CTP]]
| latest_preview_version = 2.0 [[Community_Technology_Preview#Beta|CTP]]
| latest preview_date = [[November 6]], [[2007]]
| latest_preview_date = {{release date|2007|11|06}}
| preview_url = [http://blogs.msdn.com/powershell/archive/2006/09/26/Windows-PowerShell-RC2-Now-Available.aspx PowerShell V2]
| preview_url = [http://blogs.msdn.com/powershell/archive/2006/09/26/Windows-PowerShell-RC2-Now-Available.aspx PowerShell V2]
| operating_system = [[Windows XP]], [[Windows Server 2003]], [[Windows Vista]], [[Windows Server 2008]]
| operating_system = [[Windows XP]]<br>[[Windows Server 2003]]<br>[[Windows Vista]]<br>[[Windows Server 2008]]
| platform = [[x86]], [[x86-64]] and [[Itanium]]
| platform = [[x86]], [[x86-64]] and [[Itanium]]
| language = multilanguage
| language = multilanguage
Line 20: Line 21:
| website = [http://www.microsoft.com/powershell Windows PowerShell]
| website = [http://www.microsoft.com/powershell Windows PowerShell]
}}
}}
'''Windows PowerShell''' (formerly codenamed '''Monad''' as a reference to the [[monadism]] philosophy of Leibnitz), is an extensible [[command line interface]] (CLI) shell and associated [[scripting language]] from Microsoft. It was released in 2006 and is currently available for [[Windows XP]] SP2, [[Windows Server 2003]] and [[Windows Vista]]. Furthermore, it is built into [[Windows Server 2008]] as an optional feature. <ref name="powershell-server2008">{{cite web
'''Windows PowerShell''' is an extensible [[command line interface]] shell and associated [[scripting language]] from Microsoft. It was released in 2006 and is currently available for [[Windows XP]] SP2, [[Windows Server 2003]], [[Windows Vista]] and is built into [[Windows Server 2008]] as an optional feature.

|url=http://www.microsoft.com/windowsserver2008/powershell.mspx
Windows PowerShell integrates with [[.NET Framework]] and provides an environment to perform administrative tasks by execution of ''cmdlets'' (pronounced ''commandlets'') which are specialized .NET classes implementing a particular operation, ''scripts'' which are [[function composition|composition]] of cmdlets along with [[imperative logic]], ''executables'' which are standalone applications, or by instantiating regular .NET classes.<ref name="how">{{cite web | url = http://msdn2.microsoft.com/en-us/library/ms714658.aspx | title = How Windows PowerShell works | publisher = [[MSDN]] | accessdate = 2007-11-27}}</ref> <ref name="MSDN">{{cite web | url = http://msdn.microsoft.com/msdnmag/issues/07/12/PowerShell/default.aspx | title = Extend Windows PowerShell With Custom Commands| publisher = [[MSDN]] | accessdate = 2007-11-27}}</ref> These work by accessing data in different data stores, like [[filesystem]] or [[Windows Registry|registry]], which are made available to the PowerShell runtime via Windows PowerShell ''providers''.
|title=Windows Server 2008: Windows PowerShell: Now Part of Windows Server 2008 Beta 3
|publisher=Microsoft
|date=[[November 13]] [[2006]]
|accessdate=2007-05-16
}}</ref>


Windows PowerShell also provides a hosting [[API|mechanism]] with which the Windows PowerShell runtime can be embedded inside other applications, which can then leverage Windows PowerShell functionality to implement certain operations, including those exposed via the [[GUI|graphical interface]]. This capability has been utilized by [[Microsoft Exchange Server]] 2007<ref name="how"/><ref>{{cite web | url = http://articles.techrepublic.com.com/5100-10878_11-6147304.html | title = Exchange 2007: Get used to the command line | publisher = Tech Republic | accessdate = 2007-11-28}}</ref> to expose its management functionality as PowerShell cmdlets and providers and implement the [[Graphical User Interface|graphical]] management tools as PowerShell hosts which invoke the necessary cmdlets. Other [[Microsoft]] applications including [[Microsoft SQL Server]]<ref>{{cite web | url = http://blogs.msdn.com/powershell/archive/2007/11/13/sql-server-support-for-powershell.aspx | title = SQL Server Support for PowerShell! | accessdate = 2007-11-28}}</ref> 2008 also expose their management interface via PowerShell cmdlets. In the future, [[GUI|graphical interface]]-based management applications on Windows will be layered on top of Windows PowerShell.
PowerShell integrates with [[.NET Framework]] and provides an environment to perform administrative tasks by execution of ''Cmdlets'' (pronounced ''commandlets'') which are specialized .NET classes implementing a particular operation, ''scripts'' which are [[function composition|composition]] of cmdlets along with [[imperative logic]], ''executables'' which are standalone applications, or by instantiating regular .NET classes.<ref name="how">{{cite web | url = http://msdn2.microsoft.com/en-us/library/ms714658.aspx | title = How Windows PowerShell works | publisher = [[MSDN]] | accessdate = 2007-11-27}}</ref>These work by accessing data in different data stores, like [[filesystem]] or [[Windows Registry|registry]], which are made available to the PowerShell runtime via PowerShell ''providers''.


Windows PowerShell includes its own extensive, console-based help, reminiscent of [[Manual page (Unix)|man pages]] in Unix. The help topics include help for cmdlets, providers, and concepts in PowerShell. To see the help, use the <code>Get-Help</code> cmdlet. Online help for Windows PowerShell is updated weekly in the [[Microsoft TechNet|TechNet Library]].
PowerShell also provides a hosting [[API]] using which the PowerShell runtime can be embedded inside other applications, which can then leverage PowerShell functionality to implement certain operations, including operations exposed via GUI. This capability has been utilized by [[Microsoft Exchange Server]] 2007 and [[System Center Operations Manager]] 2007 to expose their management [[API]]s as PowerShell cmdlets and providers and implement the GUI 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, though their GUI isn't yet layered on top of PowerShell. Going forward, GUI-based management applications on Windows will be based on PowerShell.


==Background==
==Background==
Every released version of [[Microsoft DOS]] and [[Microsoft Windows]] for [[personal computer]]s has featured a command line interface tool. These are <code>[[COMMAND.COM]]</code> (in installations relying on [[MS-DOS]], including Windows 9x) and <code>[[cmd.exe]]</code> (in [[Windows NT]]-based installations). Both of these are regular shells, which included only a handful of basic commands. To control anything else, a separate [[console]]-based application needs to be provided which could then be invoked from these shells. They also included a scripting language([[batch files]]) which could be used to automate some tasks. However, it could not be used to automate all the GUI functionality, in part because CLI equivalents of GUI operations, and in part because the scripting language was bare-bones, which prevented creation of complex scripts by composing available functionality. While with [[Windows Server 2003]], the former situation was improved,<ref name="pcmag-server2003">{{cite web
Every released version of [[Microsoft DOS]] and [[Microsoft Windows]] for [[personal computer]]s has featured a command-line interface tool. These are <code>[[COMMAND.COM]]</code> (in installations relying on [[MS-DOS]], including [[Windows 9x]]) and <code>[[cmd.exe]]</code> (in [[Windows NT]]-based installations). These are regular shells which include only a handful of basic commands. For other purposes, a separate [[console]]-based 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, preventing the creation of complex scripts by composing available functionality. In [[Windows Server 2003]], the situation was improved,<ref name="pcmag-server2003">{{cite web
|url = http://www.pcmag.com/article2/0,2704,1040410,00.asp
|url = http://www.pcmag.com/article2/0,2704,1040410,00.asp
|title = Windows Server 2003 Delivers Improvements All Around
|title = Windows Server 2003 Delivers Improvements All Around
Line 41: Line 38:
|publisher = [[PC Magazine]]
|publisher = [[PC Magazine]]
|quote = A standout feature here is that virtually all admin utilities now work from the command line (and most are available through telnet).
|quote = A standout feature here is that virtually all admin utilities now work from the command line (and most are available through telnet).
}}</ref> scripting support was still off the mark.
}}</ref> 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: <code>cscript.exe</code> with [[Windows Server 2003]]. It integrates with the [[Active Script|Active Script engine]] and allows scripts to be written in compatible languages, such as [[JScript]] and [[VBScript]], leveraging the [[API]]s exposed by applications via [[Component Object Model|COM]]. However, it has its own deficiencies, as well. It is not integrated with the shell, its documentation not very accessible, and it quickly gained a reputation as a system [[Vulnerability (computer science)|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]]) with their own command sets. None of them were integrated with the command shell, nor were interoperable.
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: <code>cscript.exe</code> with [[Windows Server 2003]]. It integrates with the [[Active Script|Active Script engine]] and allows scripts to be written in compatible languages, such as [[JScript]] and [[VBScript]], leveraging the [[API]]s exposed by applications via [[Component Object Model|COM]]. However, it has its own deficiencies, as well. It is not integrated with the shell, its documentation not very accessible, and it quickly gained a reputation as a system [[Vulnerability (computer science)|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 2003 Microsoft had started to develop a new shell called Monad (aka Microsoft Shell or MSH). Monad was to be 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 [[Development stage#Beta|beta release]] on [[June 17]] [[2005]], Beta 2 on [[September 11]] [[2005]] and Beta 3 on [[January 10]] [[2006]]. They announced on [[April 25]] [[2006]] that Monad was renamed to Windows PowerShell, positioning it as a significant part of their management technology offerings.<ref name="monad-renamed">{{cite web
By 2003 Microsoft had started to develop a new shell called Monad (aka Microsoft Shell or MSH). Monad was to be 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 [[Development stage#Beta|beta release]] on [[June 17]] [[2005]], Beta 2 on [[September 11]] [[2005]] and Beta 3 on [[January 10]] [[2006]]. They announced on [[April 25]] [[2006]] that Monad was renamed to Windows PowerShell, positioning it as a significant part of their management technology offerings.<ref name="monad-renamed">{{cite web
Line 55: Line 52:
|publisher=MSDN
|publisher=MSDN
}}</ref> Release Candidate 1 of PowerShell was released at the same time.
}}</ref> Release Candidate 1 of PowerShell was released at the same time.
Release Candidate 2 of PowerShell was released [[September 26]] [[2006]] and later [[Release to web|released to web]] (RTW) [[November 14]] [[2006]]. PowerShell for Vista was released on [[January 30]] [[2007]].<ref name="powershell-vista">{{cite web
Release Candidate 2 of PowerShell was released [[September 26]] [[2006]] and [[Release to web|released to web]] (RTW) on [[November 14]] [[2006]]. PowerShell for Vista was released on [[January 30]] [[2007]].<ref name="powershell-vista">{{cite web
|url=http://blogs.msdn.com/powershell/archive/2006/11/15/windows-powershell-windows-vista.aspx
|url=http://blogs.msdn.com/powershell/archive/2006/11/15/windows-powershell-windows-vista.aspx
|title=Windows PowerShell : Windows PowerShell & Windows Vista
|title=Windows PowerShell : Windows PowerShell & Windows Vista
Line 64: Line 61:
|work=Windows PowerShell team blog
|work=Windows PowerShell team blog
|publisher=MSDN
|publisher=MSDN
}}</ref> Currently a [[CTP]] release of Windows PowerShell v2.0 has been made available since [[November 6]] [[2007]].<ref name="powershell-2-ctp">{{cite web
}}</ref> A [[Community Technology Preview|CTP]] release of Windows PowerShell v2.0 has been made available since [[November 6]] [[2007]].<ref name="powershell-2-ctp">{{cite web
|url=http://blogs.msdn.com/powershell/archive/2007/11/06/the-community-technology-preview-ctp-of-windows-powershell-2-0.aspx
|url=http://blogs.msdn.com/powershell/archive/2007/11/06/the-community-technology-preview-ctp-of-windows-powershell-2-0.aspx
|title=The Community Technology Preview (CTP) of Windows PowerShell 2.0
|title=The Community Technology Preview (CTP) of Windows PowerShell 2.0
Line 77: Line 74:
==Overview==
==Overview==
===PowerShell 1.0===
===PowerShell 1.0===
Like any other [[command line interpreter|command shell]], Windows PowerShell allows for execution of commands. Commands can be either in the form of ''Cmdlets'', which are specialized [[.NET Framework|.NET]] [[Class (computer science)|classess]] designed to expose a certain functionality via PowerShell, or a regular [[executable]]. If the command is an executable file, PowerShell launches it in a separate [[Process (computing)|process]], but if it is an Cmdlet, it is executed in the PowerShell process. PowerShell also provides an interactive [[command line]] interface where the commands can be entered and where the output of the commands will be displayed. The command line interface, based on <code>[[cmd.exe]]</code> offers basic [[tab completion]] but lacks [[syntax highlighting]]. PowerShell also allows creating ''[[alias (Unix shell)|aliases]]'' for cmdlets, which are textually substituted by PowerShell with the original command. Powershell also supports command line parameters for the commands, which are either named or positional parameters for the commands. If the command is a cmdlet, then the job of binding the parameter value with the parameter is done by PowerShell itself, but for external executables, they are provided to the executable via the [[argv]] (or equivalent) variable array, the responsibility of parsing which is on the executable.
The commands Windows PowerShell executes may be in the form of ''cmdlets'', which are specialized [[.NET Framework|.NET]] [[Class (computer science)|classes]] designed expressly to expose a functionality via PowerShell, PowerShell scripts (*.ps1) or regular [[executable]]s. If a command is an executable file, PowerShell launches it in a separate [[Process (computing)|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 basic [[tab completion]] but lacks [[syntax highlighting]]. PowerShell also enables the creation of ''[[alias (Unix shell)|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 parameter value to the parameter is done by PowerShell itself, but for external executables, parameters are passed via the [[argv]] (or equivalent) variable array to be parsed by the executable.


Another concept when working with PowerShell, is a ''pipeline''. Like [[Pipeline (Unix)|Unix Pipelines]], it is used to [[Function composition|compose]] together multiple commands, by allowing the output of one command to be sent as the input to another command. A pipeline is set up by ''piping'' the output of a command (or another pipeline) to another command using the <code>|</code> operator. However, unlike its Unix counterpart, the PowerShell pipeline is an [[Pipeline (software)|object pipeline]], i.e., the data passed between cmdlets are fully [[type system|typed]] [[Object (computer science)|objects]], rather than a text stream. With text streams, the receiving command has to [[Parsing|parse]] the stream to extract the data it is interested in, using either the capabilities of the shell or using special purpose tools like [[Grep]] or [[Awk]]. But, when the data is piped as objects, the data elements encapsulated by the object retains their type, and can make each element available through separate [[Property (programming)|properties]]. So, the recipient cmdlet can directly access the data elements via the properties without implementing any parser. An object can also encapsulate certain functions that work on the contained data. These functions also become available to the recipient command for use.<ref>{{cite web | url = http://www.microsoft.com/technet/technetmag/issues/2007/07/PowerShell/default.aspx | title = Rethinking the Pipeline | accessdate = 2007-11-28}}</ref><ref>{{cite web | url = http://msdn2.microsoft.com/en-us/library/aa347685.aspx | title = Windows PowerShell Object Concepts | accessdate = 2007-11-28}}</ref> For the last cmdlet in the pipeline, PowerShell automatically pipes the output object to the <code>Write-Host</code> cmdlet, which creates a formatted text representation of the data contained in the object, and writes it to the screen. As all PowerShell objects are .NET objects, they share a <code>.ToString()</code> method, that 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, that allows the text representation of objects to be customized, by choosing what data elements to be displayed. However, for backward compatibility reasons, if external executables are used in a pipeline, it receives a text stream representing the object, as it does not integrate with the PowerShell type system.
Another concept used by PowerShell is that of a ''pipeline''. Like [[Pipeline (Unix)|Unix pipelines]], PowerShell pipelines are used to [[Function composition|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 <code>|</code> operator. But unlike its Unix counterpart, the PowerShell pipeline is an [[Pipeline (software)|object pipeline]]; that is, the data passed between cmdlets are fully [[type system|typed]] [[Object (computer science)|objects]], rather than byte streams. Byte streams require the receiving command to [[Parsing|parse]] them to extract the data it needs, using either the capabilities of the shell or special-purpose tools, such as [[grep]] and [[AWK (programming language)|AWK]]. But when data is piped as objects, the elements they encapsulate retain their types, making them distinguishable through separate [[Property (programming)|properties]]. The recipient cmdlet can then access the data elements by their properties without implementing a parser. An object can also encapsulate certain functions that work on the contained data. These also become available to the recipient command for use.<ref>{{cite web | url = http://www.microsoft.com/technet/technetmag/issues/2007/07/PowerShell/default.aspx | title = Rethinking the Pipeline | accessdate = 2007-11-28}}</ref><ref>{{cite web | url = http://msdn2.microsoft.com/en-us/library/aa347685.aspx | title = Windows PowerShell Object Concepts | accessdate = 2007-11-28}}</ref> For the last cmdlet in a pipeline, PowerShell automatically pipes its output object to the <code>Write-Host</code> cmdlet, which creates a formatted text representation of its data, writing it to the screen.<ref>{{cite web | url = http://blogs.msdn.com/powershell/archive/2006/04/30/586973.aspx | title = How PowerShell Formatting and Outputting REALLY works| accessdate = 2007-11-28}}</ref><ref>{{cite web | url = http://blogs.msdn.com/powershell/archive/2006/06/21/641738.aspx | title = More - How does PowerShell formatting really work?| accessdate = 2007-11-28}}</ref>


Because all PowerShell objects are .NET objects, they share a <code>.ToString()</code> 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 external executables are used in a pipeline, it receives a text stream representing the object, and does not integrate with the PowerShell type system.
The PowerShell type, ''Extended Type System'' (''ETS'') system is based on the .NET type system, but includes certain extensions. For example, it allows creation of different views of objects, by only exposing a subset of the data fields, properties and methods, as well as specify custom formatting and sorting behavior. These views are mapped to the original object using an [[XML]] based language.<ref>{{cite web | url = http://msdn2.microsoft.com/en-us/library/ms714419.aspx | title = Windows PowerShell Extended Type System | accessdate = 2007-11-28}}</ref>


The PowerShell ''Extended Type System'' (''ETS'') is based on the .NET type system, but with certain extensions. 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 an [[XML]]-based language.<ref>{{cite web | url = http://msdn2.microsoft.com/en-us/library/ms714419.aspx | title = Windows PowerShell Extended Type System | accessdate = 2007-11-28}}</ref>
====Cmdlet====
Cmdlets are specialized command in the PowerShell environment, that implements a specific functionality. These are the native commands in the PowerShell stack. Cmdlets follow a ''<verb>''-''<noun>'' naming patters, such as ''Get-ChildItem'', which, according to Microsoft, makes them self-descriptive.<ref name="cmdlets">{{cite web | url = http://msdn2.microsoft.com/en-us/library/ms714395.aspx | title = Windows PowerShell Cmdlets | accessdate = 2007-11-28}}</ref> Cmdlets output the results as objects or collections of objects (including arrays), and can optionally receive the input it will work on as an object (which makes it suitable for use as a recipient cmdlet in a pipeline). While PowerShell allows arrays and other collection of objects to be written onto the pipeline, a Cmdlet always processes objects individually. For collection objects, PowerShell invokes the Cmdlet on each object in the collection, sequentially.<ref name="cmdlets"/>


====Cmdlets====
Cmdlets are specialized .NET [[class (computing)|classes]], which the PowerShell runtime instantiates and invokes when the cmdlet is being run. Cmdlets derive from either <code>Cmdlet</code> or <code>PSCmdlet</code>, with the latter being used when the Cmdlet needs to interact with the PowerShell runtime.<ref name="cmdlets"/> These base classes specify certain methods - <code>BeginProcessing()<code>, <code>ProcessRecord()</code> and <code>EndProcessing()</code> - one of which the Cmdlet implementation overrides to provide the functionality. Whenever a cmdlet is run, these methods are invoked by PowerShell, in sequence, with <code>ProcessRecord()</code> called if it receives pipeline input.<ref name="firstcmdlet">{{cite web | url = http://msdn2.microsoft.com/en-us/library/ms714622.aspx |title = Creating Your First Cmdlet | accessdate = 2007-11-28}}</ref> If a collection of objects are piped, the method is invoked for each object in collection. The class implementing the Cmdlet must have one .NET [[Attribute (computing)|attribute]] - <code>CmdletAttribute</code> - which specifies the verb and the noun that will make up the name of the cmdlet. Common verbs are provided as an [[enum]].
Cmdlets are specialized commands in the PowerShell environment that implement specific functions. These are the native commands in the PowerShell stack. Cmdlets follow a ''<verb>''-''<noun>'' naming pattern, such as ''Get-ChildItem'', helping to make them (according to Microsoft) self-descriptive.<ref name="cmdlets">{{cite web | url = http://msdn2.microsoft.com/en-us/library/ms714395.aspx | title = Windows PowerShell Cmdlets | accessdate = 2007-11-28}}</ref> Cmdlets output their results as objects, or collections thereof (including arrays), and can optionally receive input in that form, making them suitable for use as recipients in a pipeline. But while PowerShell allows arrays and other collection of objects to be written to the pipeline, cmdlets always process objects individually. For collections of objects, PowerShell invokes the cmdlet on each object in the collection, in sequence.<ref name="cmdlets"/>


Cmdlets are specialized .NET [[class (computing)|classes]], which the PowerShell runtime instantiates and invokes when they are run. Cmdlets derive either from <code>Cmdlet</code> or from <code>PSCmdlet</code>, the latter being used when the cmdlet needs to interact with the PowerShell runtime.<ref name="cmdlets"/> These base classes specify certain methods - <code>BeginProcessing()<code>, <code>ProcessRecord()</code> and <code>EndProcessing()</code> - 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 <code>ProcessRecord()</code> being called if it receives pipeline input.<ref name="firstcmdlet">{{cite web | url = http://msdn2.microsoft.com/en-us/library/ms714622.aspx |title = Creating Your First Cmdlet | accessdate = 2007-11-28}}</ref> If a collection of objects are piped, the method is invoked for each object in the collection. The class implementing the Cmdlet must have one .NET [[Attribute (computing)|attribute]] - <code>CmdletAttribute</code> - which specifies the verb and the noun that make up the name of the cmdlet. Common verbs are provided as an [[enum]].
If the cmdlet receives either pipeline input or command line parameter input, there must be a corresponding [[Property (programming)|property]] in the class, with a [[Mutator method|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 where the functionality is implemented. Properties that map to command line parameters are marked by <code>ParameterAttribute</code><ref>{{cite web | url = http://msdn2.microsoft.com/en-us/library/ms714663.aspx | title = Adding parameters That Process Command Line Input | accessdate = 2007-11-28}}</ref> and are set before the call to <code>BeginProcessing()</code>. Those which map to pipeline input are also flanked by <code>ParameterAttribute</code> but with <code>ValueFromPipeline</code> attribute parameter set.<ref>{{cite web | url = http://msdn2.microsoft.com/en-us/library/ms714597.aspx | title = Adding parameters That Process Pipeline Input | accessdate = 2007-11-28}}</ref>


If a cmdlet receives either pipeline input or command-line parameter input, there must be a corresponding [[Property (programming)|property]] in the class, with a [[Mutator method|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 <code>ParameterAttribute</code><ref>{{cite web | url = http://msdn2.microsoft.com/en-us/library/ms714663.aspx | title = Adding parameters That Process Command Line Input | accessdate = 2007-11-28}}</ref> and are set before the call to <code>BeginProcessing()</code>. Those which map to pipeline input are also flanked by <code>ParameterAttribute</code>, but with the <code>ValueFromPipeline</code> attribute parameter set.<ref>{{cite web | url = http://msdn2.microsoft.com/en-us/library/ms714597.aspx | title = Adding parameters That Process Pipeline Input | accessdate = 2007-11-28}}</ref>
The implementation of these Cmdlet classes can refer to any [[.NET]] [[API]] and can be in any [[.NET languages|.NET language]]. In addition, PowerShell makes certain APIs available, such as <code>WriteObject()</code>, which is used to access PowerShell specific functionality such as writing resultant objects to the pipeline. Cmdlets can use .NET data access [[API]]s directly, or use the PowerShell infrastructure of PowerShell ''Providers'', which make data stores addressible using a unique [[Path (computing)|path]]. Different data stores are surfaced using drive letters and hieararchies in them addressed as directories. Windows PowerShell ships with providers for the [[file system]], and [[Windows Registry|registry]].<ref>{{cite web | url = http://msdn2.microsoft.com/en-us/library/ms714460.aspx | title = Windows PowerShell Providers | accessdate = 2007-11-28}}</ref> Windows PowerShell also includes various Cmdlets for managing various [[Microsoft Windows|Windows]] systems including the [[file system]], or using [[Windows Management Instrumentation|WMI]] to control Windows components. Other applications can register with PowerShell other Cmdlets that allow them to be managed using Windows PowerrShell, and if they enclose any datastore (such as databases), they can add specific providers as well.

The implementation of these cmdlet classes can refer to any [[.NET]] [[API]] and may be in any [[.NET languages|.NET language]]. In addition, PowerShell makes certain APIs available, such as <code>WriteObject()</code>, which is used to access PowerShell-specific functionality, such as writing resultant objects to the pipeline. Cmdlets can use .NET data access [[API]]s directly or use the PowerShell infrastructure of PowerShell ''Providers'', which make data stores addressable using unique [[Path (computing)|paths]]. Data stores are exposed using drive letters, and hierarchies within them, addressed as directories. Windows PowerShell ships with providers for the [[file system]], and [[Windows Registry|registry]].<ref>{{cite web | url = http://msdn2.microsoft.com/en-us/library/ms714460.aspx | title = Windows PowerShell Providers | accessdate = 2007-11-28}}</ref> Windows PowerShell also includes various cmdlets for managing various [[Microsoft Windows|Windows]] systems, including the [[file system]], or using [[Windows Management Instrumentation]] to control [[List of Microsoft Windows components|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.


====Scripting====
====Scripting====
Windows PowerShell includes an untyped [[scripting language]], somewhat similar to [[C sharp|C#]], that can be used to perform complex operations by using the cmdlets [[imperative programming|imperatively]]. The scripting language supports variables, functions, branching (if-then-else), loops (while, do, for and foreach), error handling as well as integration with .NET. Variables in PowerShell scripts start with <code>$</code> and 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 either be [[primitive type]]s or objects. Strings can either be encased in single quotes or double quotes; with the former, variables will be expanded even if they are inside the single quotes. Using the variable syntax, if a path to a file is enclosed in <code>{…}</code> preceded by <code>$</code> (as in <code>${C:\foo.txt}</code>, it will refer to the contents of the file. If it is used as an [[l-value]], anything assigned to it will get written to the file. And when used as [[r-value]], the value will be read of the file. If an object is assigned, it is serialized before storing.
Windows PowerShell includes an untyped [[scripting language]] which can implement complex operations using cmdlets [[imperative programming|imperatively]]. The scripting language supports variables, functions, branching (if-then-else), loops (while, do, for, and foreach), and error handling, as well as integration with .NET. Variables in PowerShell scripts have names that start with <code>$</code>; 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 type]]s or objects. Strings can be enclosed either in single quotes or in double quotes; in the former case, 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 <code>${C:\foo.txt}</code>), 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 <code>.</code> notation, like C# syntax. PowerShell provides some special variables such as <code>$args</code>, which is an array of all the command line arguments passed to a function from the command line, and <code>$_</code>, which refers to the current object in the pipeline.<ref>{{cite web | url = http://www.computerperformance.co.uk/powershell/powershell_variables.htm | title = Introduction to Windows PowerShell's Variables | accesdate = 2007-11-28}}</ref> PowerShell also provides [[array]]s and [[associative array]]s. The PowerShell scripting language also immediately evaluates arithmetic expressions, when entered at the command line. It parses common abbreviations such as GB, MB and KB.
Object members can be accessed using <code>.</code> notation, as in C# syntax. PowerShell provides special variables, such as <code>$args</code>, which is an array of all the command line arguments passed to a function from the command line, and <code>$_</code>, which refers to the current object in the pipeline.<ref>{{cite web | url = http://www.computerperformance.co.uk/powershell/powershell_variables.htm | title = Introduction to Windows PowerShell's Variables | accessdate = 2007-11-28}}</ref> PowerShell also provides [[array]]s and [[associative array]]s. 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.


PowerShell also allows creation of functions using the <code>function</code> keyword, which can contain parameters as well. Powershell provides two syntaxes for invoking a function:
Using the <code>function</code> keyword, PowerShell provides for the creation of functions, which can take parameters. It provides two syntaxes for invoking a function:
#<code>''<function> <param1> <param2> …'''</code>: In this case, the function need not define the parameters it accepts; the parameters will be passed as an array accessible from inside the function via the <code>$args</code> array.<ref>{{cite web | url = http://mspowershell.blogspot.com/2006/11/functions-in-powershell.html | title = Functions in PowerShell | accessdate = 2007-11-28}}</ref>
#<code>''<function> <param1> <param2> …'''</code>: In this case, the function need not define the parameters it accepts; the parameters will be passed as an array accessible from inside the function via the <code>$args</code> array.<ref>{{cite web | url = http://mspowershell.blogspot.com/2006/11/functions-in-powershell.html | title = Functions in PowerShell | accessdate = 2007-11-28}}</ref>
#<code>''<function>(<param1>, <param2>)''</code>: In this case, the function declaration must specify the parameters it accepts and their types. The parameters passed will be bound to the parameter variables when the function is called.<ref>{{cite web | http://weblogs.asp.net/soever/archive/2006/11/29/powershell-calling-a-function-with-parameters.aspx | title = Calling a Function with Parameters | accessdate = 2007-11-28}}</ref>
#<code>''<function>(<param1>, <param2>)''</code>: In this case, the function declaration must specify the parameters it accepts, and their types. The parameters passed will be bound to the parameter variables when the function is called.<ref>{{cite web | url = http://weblogs.asp.net/soever/archive/2006/11/29/powershell-calling-a-function-with-parameters.aspx | title = Calling a Function with Parameters | accessdate = 2007-11-28}}</ref>
PowerShell also allows any .NET method to be called, by providing their namespaces enclosed in <code>[]</code> and then using <code>::</code> to demarcate the static method.<ref name="dotnet">{{cite web | url = http://msdn.microsoft.com/msdnmag/issues/07/05/TestRun/default.aspx | title = Lightweight Testing with Windows PowerShell | accessdate = 2007-11-28}}</ref> For example,
PowerShell allows any .NET methods to be called by providing their namespaces enclosed in brackets (<code>[]</code>), and then using a pair of colons (<code>::</code>) to indicate the static method.<ref name="dotnet">{{cite web | url = http://msdn.microsoft.com/msdnmag/issues/07/05/TestRun/default.aspx | title = Lightweight Testing with Windows PowerShell | accessdate = 2007-11-28}}</ref> For example,
<code>[System.Console]::WriteLine("PowerShell")</code>
<code>[System.Console]::WriteLine("PowerShell")</code>
Objects are created using the <code>New-Object</code> cmdlet. Calling methods of .NET objects are done using the regular <code>.</code> notation.<ref name="dotnet"/>
Objects are created using the <code>New-Object</code> cmdlet. Calling methods of .NET objects is accomplished by using the regular <code>.</code> notation.<ref name="dotnet"/>


For error handling, PowerShell provides .NET style <code>Try…Catch…Finally</code> blocks. In case of errors, objects containing errors about the error (<code>Exception</code> object) are thrown, which are caught using the <code>trap</code>. However, the action-or-error is configurable; in case of an error PowerShell can be configured to silently resume execution, without trapping the exception.<ref>{{cite web | url = http://huddledmasses.org/trap-exception-in-powershell | title = Trap [Exception] { “In PowerShell” } | accessdate = 2007-11-28}}</ref>
For error handling, PowerShell provides .NET style <code>Try…Catch…Finally</code> blocks. In case of errors, objects containing errors about the error (<code>Exception</code> object) are thrown, which are caught using the <code>trap</code>. However, the action-or-error is configurable; in case of an error PowerShell can be configured to silently resume execution, without trapping the exception.<ref>{{cite web | url = http://huddledmasses.org/trap-exception-in-powershell | title = Trap [Exception] { “In PowerShell” } | accessdate = 2007-11-28}}</ref>


Scripts written using PowerShell can be persisted across sessions in a <code>.ps1</code> 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 bound to them. Pipeline objects can be passed between functions, scripts and cmdlets seamlessly. However, by default, script execution is disabled. They must be enabled explicitly.<ref>{{cite web | url = http://www.microsoft.com/technet/scriptcenter/topics/winpsh/manual/run.mspx | title = Running Windows PowerShell Scripts | accessdate = 2007-11-28}}</ref> PowerShell scripts can be [[code signing|signed]] to verify their integrity. Scripts are subject to .NET [[Code Access Security|CAS]].
Scripts written using PowerShell can be made to persist across sessions in a <code>.ps1</code> 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.<ref>{{cite web | url = http://www.microsoft.com/technet/scriptcenter/topics/winpsh/manual/run.mspx | title = Running Windows PowerShell Scripts | accessdate = 2007-11-28}}</ref> PowerShell scripts can be [[code signing|signed]] to verify their integrity, and are subject to .NET [[Code Access Security]].


====Hosting====
====Hosting====
Line 114: Line 113:


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 [[interpreter|interprets]] the scripts entered at command line and creates the necessary <code>Pipeline</code> objects and invokes them.
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 [[interpreter|interprets]] the scripts entered at command line and creates the necessary <code>Pipeline</code> objects and invokes them.

====Public reception====
Public reception of Windows PowerShell 1.0 has generally been quite positive.
In his Windows Server 2008 review technology reporter [[Paul Thurrott]] states:
{{cquote|PowerShell is a complex but technically impressive environment, with support for discoverable .NET-based objects, properties, and methods. It provides all of the power of UNIX command line environments with none of the inconsistencies.<ref>[http://www.winsupersite.com/reviews/win2008.asp Windows Server 2008 Review]</ref>}}
According to Microsoft, PowerShell has had almost a million downloads in its first six months.
<ref>[http://blogs.msdn.com/powershell/archive/2007/06/04/powershell-hits-a-million-downloads-in-the-first-six-months.aspx PowerShell Hits a Million Downloads in the First Six Months]</ref>
There is also a growing list of products that are shipping with PowerShell support.


===PowerShell 2.0===
===PowerShell 2.0===
{{future software}}
{{future software}}
[[Image:GPowerShell.PNG|thumb|right|Graphical PowerShell, with multiple open ''RunSpaces'' and the GridView window]]
Microsoft is working on the next version of PowerShell and has made a [[CTP]] release of the same publicly available. It includes changes to the scripting language and hosting API, in addition to including a number of cmdlets. A non-exhaustive list of the new features is:<ref>{{cite web | url = http://blogs.msdn.com/powershell/archive/2007/11/06/what-s-new-in-ctp-of-powershell-2-0.aspx | title = What's New in CTP of PowerShell 2.0 | accessdate = 2007-11-28}}</ref>
Microsoft is working on the next version of PowerShell and has made a [[Community Technology Preview|CTP]] release of the same publicly available. It includes changes to the scripting language and hosting API, in addition to including a number of cmdlets. A non-exhaustive list of the new features is:<ref>{{cite web | url = http://blogs.msdn.com/powershell/archive/2007/11/06/what-s-new-in-ctp-of-powershell-2-0.aspx | title = What's New in CTP of PowerShell 2.0 | accessdate = 2007-11-28}}</ref>
# '''PowerShell Remoting''': Using [[WS-Management]], PowerShell 2.0 allows scripts and cmdlets to be invoked from a remote client.
# '''PowerShell Remoting''': Using [[WS-Management]], PowerShell 2.0 allows scripts and cmdlets to be invoked on a remote machine or a large set of remote machines.
#'''Background Jobs''': Also called a '''PSJob''', it allows a command sequence (script) or pipeline to be invoked asynchronously. A PSJob cannot include interactive cmdlets.
#'''Background Jobs''': Also called a '''PSJob''', it allows a command sequence (script) or pipeline to be invoked asynchronously. Jobs can be run on the local machine or on multiple remote machines. A PSJob cannot include interactive cmdlets.
#'''ScriptCmdlets''': These are cmdlets written using the PowerShell scripting language.
#'''ScriptCmdlets''': These are cmdlets written using the PowerShell scripting language.
#'''SteppablePipelines''': This allows the user to control when the <code>BeginProcessing()</code>, <code>ProcessRecord()</code> and <code>EndProcessing()</code> functions are called.
#'''SteppablePipelines''': This allows the user to control when the <code>BeginProcessing()</code>, <code>ProcessRecord()</code> and <code>EndProcessing()</code> functions of a cmdlet are called.
#'''Data Language''': A domain-specific language embedded as a part of the PowerShell scripting language, that allows data definitions to be decoupled from the scripts and allow localized string resources to be imported into the script at runtime.
#'''Data Language''': A domain-specific subset of the PowerShell scripting language, that allows data definitions to be decoupled from the scripts and allow localized string resources to be imported into the script at runtime.
#'''Script Debugging''': It allows [[breakpoint]]s to be set in a PowerShell script or function. It includes a set of cmdlets to control the breakpoints via script.
#'''Script Debugging''': It allows [[breakpoint]]s to be set in a PowerShell script or function. Breakpoints can be set on lines, line & columns, commands and read or write access of variables. It includes a set of cmdlets to control the breakpoints via script.
#'''New Cmdletes''': Including '''Out-GridView''', which displays tabular data in the [[Windows Presentation Foundation|WPF]] [[Grid view|GridView]] object.
#'''New Cmdlets''': Including '''Out-GridView''', which displays tabular data in the [[Windows Presentation Foundation|WPF]] [[Grid view|GridView]] object.
#'''New Operators''': -Split -Join and @ operators.
#'''New APIs''': The new APIs range from handing more control over the PowerShell parser and runtime to the host, to creating and managing collection of Runspaces (Runspace Pools).
#'''New APIs''': The new APIs range from handing more control over the PowerShell parser and runtime to the host, to creating and managing collection of Runspaces (Runspace Pools) as well as the ability to create restricted Runspaces which only allow a configured subset of PowerShell to be invoked.
#'''Graphical PowerShell''': PowerShell 2.0 includes a GUI-based PowerShell host that provides integrated debugger, [[syntax highlighting]] and upto 8 PowerShell consoles (Runspaces) in a tabbed UI, as well as to run only the selected parts in a script.. However, it is a very early release which suffers from performance problems with large scripts and does not include tab completion.
#'''Graphical PowerShell''': PowerShell 2.0 includes a GUI-based PowerShell host that provides integrated debugger, [[syntax highlighting]] and up to 8 PowerShell consoles (Runspaces) in a tabbed UI, as well as to run only the selected parts in a script.. However, it is a very early release which suffers from performance problems with large scripts and does not include tab completion.


==Cmdlets==
==Cmdlets==
Line 185: Line 194:
|[[echo (computing)|echo]]
|[[echo (computing)|echo]]
|echo
|echo
|Print strings, variables etc. to screen
|Print strings, variables etc. to standard output
|-
|-
|Pop-Location
|Pop-Location
Line 265: Line 274:


==Application support==
==Application support==
{| class="wikitable" align="center"
{| class="wikitable" style="text-align: center;"
|-
|-
! Application
! Application
Line 294: Line 303:
|2007
|2007
|{{yes}}
|{{yes}}
|{{no}}
|{{yes}}
|{{no}}
|{{no}}
|-
|-
Line 301: Line 310:
|{{yes}}
|{{yes}}
|{{yes}}
|{{yes}}
|{{no}}
|{{yes}}
|-
|-
|[[System Center Data Protection Manager]]
|[[System Center Data Protection Manager]]
Line 314: Line 323:
|{{yes}}
|{{yes}}
|{{no}}
|{{no}}
|-
|Microsoft Transporter Suite for [[IBM Lotus Domino|Lotus Domino]]<ref>{{cite web | url = http://www.microsoft.com/downloads/details.aspx?familyid=35fc4205-792b-4306-8e4b-0de9cce72172&displaylang=en | title = Microsoft Transporter Suite for Lotus Domino | accessdate = 2008-03-07}}</ref>
|08.02.0012
|{{yes}}
|{{no}}
|{{no}}
|-
|[[IBM WebSphere MQ]]<ref>{{cite web | url = http://www-1.ibm.com/support/docview.wss?rs=171&uid=swg24017698 | title = MO74: WebSphere MQ - Windows Powershell Library | accessdate = 2007-12-05}}</ref>
|6.0.2.2
|{{yes}}
|{{no}}
|{{no}}
|-
|[[Quest Software|Quest Management Shell for Active Directory]]<ref>{{cite web | url = http://www.quest.com/activeroles-server/arms.aspx | title = PowerShell Commands for Active Directory Quest Software | accessdate = 2007-12-05}}</ref>
|1.0.5
|{{yes}}
|{{no}}
|{{no}}
|-
|Special Operations Software Specops Command<ref>{{cite web | url = http://www.specopssoft.com/powershell/ | title = PowerShell Remoting through Group Policy | accessdate = 2007-12-07}}</ref>
|1.0
|{{yes}}
|{{no}}
|{{yes}}
|}
|}


Line 319: Line 352:
*[[Comparison of computer shells]]
*[[Comparison of computer shells]]
*[[Comparison of programming languages]]
*[[Comparison of programming languages]]
*[[Web-Based Enterprise Management]]
*[[Common Information Model (computing)|Common Information Model]]


==References==
==References==
{{reflist}}
{{reflist|2}}


==Books==
==Books==
*{{cite book|url=http://www.manning.com/payette/|title=Windows PowerShell in Action|first=Bruce|last=Payette|id=ISBN 1-932394-90-7|quote=a founding member of the Windows PowerShell team and one of the key designers of the Windows PowerShell language}}
*{{cite book|url=http://www.manning.com/payette/|title=Windows PowerShell in Action|first=Bruce|last=Payette|id=ISBN 1-932394-90-7}}
*{{cite book|title=Professional Windows Powershell Programming: Snapins, Cmdlets, Hosts and Providers|first=Arul|last=Kumaravel|id=ISBN 0470173939|quote=Windows PowerShell Development Manager at Microsoft}}
*{{cite book|url=http://www.oreilly.com/catalog/windowspowershell/|title=Windows PowerShell Quick Reference|first=Lee|last=Holmes|id=ISBN 0-596-52813-2}}
*{{cite book|url=http://www.oreilly.com/catalog/powershell/|title=Monad - Introducing the MSH Command Shell and Language (the ''Toad book''|first=Andy|last=Oakley|id=ISBN 0-596-10009-4}}
*{{cite book|url=http://www.oreilly.com/catalog/9780596528492/index.html|title=Windows PowerShell Cookbook|first=Lee|last=Holmes|id=ISBN 0-596-52849-3}}
*{{cite book|url=http://nexus.realtimepublishers.com/EBMPS.htm|title=An Introduction to Microsoft® PowerShell™|first=Don|last=Jones}}
*{{cite book|url=http://www.wrox.com/WileyCDA/WroxTitle/productCd-0471946931.html|title=Professional Windows PowerShell|first=Andrew|last=Watt|id=ISBN 0-471-94693-1}}
*{{cite book|url=http://www.sapienpress.com/powershell.asp|title=Windows PowerShell™: TFM®|first=Don|last=Jones|coauthors=Jeffery Hicks|id=ISBN 0-9776597-1-2}}
*{{cite book|url=http://www.oreilly.com/catalog/windowspowershell/|title=Windows PowerShell Quick Reference|first=Lee|last=Holmes|id=ISBN 0-596-52813-2|quote=a developer on the Windows PowerShell team}}
*{{cite book|url=http://www.oreilly.com/catalog/9780596528492/|title=Windows PowerShell: The Definitive Guide: Rough Cuts Version|first=Lee|last=Holmes|id=ISBN 0-596-51432-8|quote=a developer on the Windows PowerShell team}}
*{{cite book|title=Microsoft Windows Powershell Programming for the Absolute Beginner|first=Jerry Lee|last=Ford Jr|id=ISBN 1-59863-354-6}}
*{{cite book|url=http://www.wrox.com/WileyCDA/WroxTitle/productCd-0471946931.html|title=Professional Windows PowerShell|first=Andrew|last=Watt|quote=Windows PowerShell MVP|id=ISBN 0-471-94693-1}}
*{{cite book|url=http://www.amazon.com/dp/0672329530/|title=Microsoft Powershell Unleashed|first=Tyson|last=Kopczynski|id=ISBN 0672329530}}
*{{cite book|url=http://www.amazon.com/dp/0672329530/|title=Microsoft Powershell Unleashed|first=Tyson|last=Kopczynski|id=ISBN 0672329530}}
*{{cite book|url=http://www.microsoft.com/MSPress/books/10329.aspx|title=Microsoft® Windows PowerShell™ Step By Step|first=Ed|last=Wilson|id=ISBN 0-7356-2395-3|quote=Microsoft’s leading scripting trainer}}
*{{cite book|url=http://www.microsoft.com/MSPress/books/10329.aspx|title=Microsoft® Windows PowerShell™ Step By Step|first=Ed|last=Wilson|id=ISBN 0-7356-2395-3}}
*{{cite book|url=http://www.course.com/catalog/product.cfm?isbn=978-1-59863-354-2|title=Microsoft Windows Powershell Programming for the Absolute Beginner |first=Jerry Lee Jr|last=Ford|id=ISBN 1-59863-354-6}}

*{{cite book|url=http://www.oreilly.com/catalog/powershell/|title=Monad (AKA PowerShell)|first=Andy|last=Oakley|id=ISBN 0-596-10009-4}}
*{{cite book|url=http://www.scriptingoutpost.com/ProductInfo.aspx?productid=BK-TFM-PSH|title=Windows PowerShell: TFM|first=Don|last=Jones|id=ISBN 0-9776597-2-0}}
==External links==
==External links==
* [http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx PowerShell homepage]
* [http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx PowerShell homepage]
* [http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx How to Download Windows PowerShell 1.0]
* [http://blogs.msdn.com/powershell/ Windows PowerShell Team Blog]
* [http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx Scripting with Windows PowerShell]
* [http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx Scripting with Windows PowerShell]
* [http://msdn2.microsoft.com/en-us/library/ms714658.aspx How Windows PowerShell Works]
* [http://blogs.msdn.com/powershell/archive/2007/03/19/monad-manifesto-the-origin-of-windows-powershell.aspx Monad Manifesto - The Origin of Windows PowerShell]
* [http://www.microsoft.com/technet/technetmag/issues/2005/11/Scripting/default.aspx ''Monad: The Future of Windows Scripting''] - an article in TechNet Magazine by Thomas Lee.

===Windows PowerShell team===
* [http://blogs.msdn.com/powershell/ Windows PowerShell Team Blog]
* [http://channel9.msdn.com/tags/PowerShell Channel9 Interviews/Demos with Jeffrey Snover] - the Architect of Windows PowerShell
* [http://channel9.msdn.com/tags/PowerShell Channel9 Interviews/Demos with Jeffrey Snover] - the Architect of Windows PowerShell
* [http://port25.technet.com/archive/2007/02/08/powershell-in-action-hank-interviews-bruce-payette.aspx Port25.TechNet.com Interview with Bruce Payette] - one of the founders of the Powershell team and co-designer of the PowerShell language
* [http://www.microsoft.com/technet/scriptcenter/resources/interviews/snover.mspx TechNet Script Center Interview with Jeffrey Snover] - the Architect of Windows PowerShell
* [http://blogs.msdn.com/powershell/archive/2006/08/03/687838.aspx ''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.
* [http://blogs.msdn.com/powershell/archive/2006/08/03/687838.aspx ''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.
* [http://www.leeholmes.com/blog/MonadAndTheFirstVistaVirus.aspx ''Monad and the "First Vista Virus"] - a clarification by Lee Holmes, a developer on the Windows PowerShell Team


===3rd-party tools===
===3rd-party tools===
* [http://www.powergui.org PowerGUI] Extensible graphical administrative console for managing systems based on Windows PowerShell.
* [http://www.powershell.com Powershell.com] - Powershell Analyzer and Powershell Plus - Powershell Hosting, Editor and Debugging Products.
* [http://www.powershell.com Powershell.com] - Powershell Analyzer and Powershell Plus - Powershell Hosting, Editor and Debugging Products.
* [http://www.codeplex.com/PowerShellCX PowerShell Community Extensions]
* [http://www.powergui.org PowerGUI Community] - PowerGUI is an extensible graphical administrative console for managing systems based on Windows PowerShell.
* [http://justarandomgeek.googlepages.com/posh-sudo sudo for Powershell] - run specific commands as an administrator on Windows Vista
* [http://www.codeplex.com/powershellremoting PowerShell Remoting] - a light-weighted server-client application to connect to remote PowerShell host and run script interactively.


===PowerShell providers===
===PowerShell providers===
Line 360: Line 386:
* [http://www.codeplex.com/PSSharePoint PowerShell SharePoint Provider] - PowerShell SharePoint Provider
* [http://www.codeplex.com/PSSharePoint PowerShell SharePoint Provider] - PowerShell SharePoint Provider
* [http://www.bdewey.com/?p=182 OneNote PowerShell Provider] - OneNote PowerShell Provider
* [http://www.bdewey.com/?p=182 OneNote PowerShell Provider] - OneNote PowerShell Provider
* [http://www.codeplex.com/NewsGatorPSProvider NewsGator Powershell Provider] - NewsGator Powershell Provider
* [http://www.codeplex.com/psmobile Windows Mobile PowerShell Provider] - Windows Mobile PowerShell Provider
* [http://www.codeplex.com/psmobile Windows Mobile PowerShell Provider] - Windows Mobile PowerShell Provider


[[Category:.NET programming languages]]
===Users groups and communities===
[[Category:Curly bracket programming languages]]
* [http://www.powershellcommunity.org PowerShellCommunity.Org] - an independent, open community dedicated to increasing the awareness and use of Microsoft Windows PowerShell.
[[Category:Dynamically-typed programming languages]]

[[Category:Interpreters (computing)]]
===Tutorial===
[[Category:Windows administration]]
* [http://arstechnica.com/guides/other/msh.ars/1 Ars Technica] - A guided tour of the Microsoft Command Shell
[[Category:Object-oriented programming languages]]
* [http://powershelllive.com/blogs/lunch/default.aspx Mastering PowerShell in your Lunch Break] - a step by step introduction to powershell by Dr Tobias Weltner ( Powershell MVP)
[[Category:Procedural programming languages]]
[[Category:Scripting languages]]
[[Category:Text-oriented programming languages]]
[[Category:Command shells]]


[[cs:Windows PowerShell]]
[[cs:Windows PowerShell]]
Line 381: Line 410:
[[ru:Windows PowerShell]]
[[ru:Windows PowerShell]]
[[fi:Windows PowerShell]]
[[fi:Windows PowerShell]]



{{Windows Components}}
{{Windows Components}}

Revision as of 16:52, 28 March 2008

Windows PowerShell
Developer(s)Microsoft Corporation
Initial releaseNovember 14, 2006
Stable release
1.0 / November 14, 2006 (2006-11-14)
Preview release
2.0 CTP / November 6, 2007 (2007-11-06)
Repository
Operating systemWindows XP
Windows Server 2003
Windows Vista
Windows Server 2008
Platformx86, x86-64 and Itanium
Available inmultilanguage
TypeOperating system shell
LicenseMS-EULA
WebsiteWindows PowerShell

Windows PowerShell is an extensible command line interface shell and associated scripting language from Microsoft. It was released in 2006 and is currently available for Windows XP SP2, Windows Server 2003, Windows Vista and is built into Windows Server 2008 as an optional feature.

Windows PowerShell integrates with .NET Framework and provides an environment to perform administrative tasks by execution of cmdlets (pronounced commandlets) which are specialized .NET classes implementing a particular operation, scripts which are composition of cmdlets along with imperative logic, executables which are standalone applications, or by instantiating regular .NET classes.[1] [2] These work by accessing data in different data stores, like 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, which can 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[1][3] 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[4] 2008 also expose their management interface via PowerShell cmdlets. In the future, graphical interface-based management applications on Windows will be layered on top of Windows PowerShell.

Windows PowerShell includes its own extensive, console-based help, reminiscent of man pages in Unix. The help topics include help for cmdlets, providers, and concepts in PowerShell. To see the help, use the Get-Help cmdlet. Online help for Windows PowerShell is updated weekly in the TechNet Library.

Background

Every released version of Microsoft DOS and Microsoft Windows for personal computers has featured a command-line interface tool. These are COMMAND.COM (in installations relying on MS-DOS, including Windows 9x) and cmd.exe (in Windows NT-based installations). These are regular shells which include only a handful of basic commands. For other purposes, a separate console-based 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, preventing the creation of complex scripts by composing available functionality. In Windows Server 2003, the situation was improved,[5] 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 with Windows Server 2003. 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 has its own deficiencies, as well. It is not integrated with the shell, its documentation 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 2003 Microsoft had started to develop a new shell called Monad (aka Microsoft Shell or MSH). Monad was to be 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. They announced on April 25 2006 that Monad was renamed to Windows PowerShell, positioning it as a significant part of their management technology offerings.[6] Release Candidate 1 of PowerShell was released at the same time. Release Candidate 2 of PowerShell was released September 26 2006 and released to web (RTW) on November 14 2006. PowerShell for Vista was released on January 30 2007.[7] A CTP release of Windows PowerShell v2.0 has been made available since November 6 2007.[8]

Overview

PowerShell 1.0

The commands Windows PowerShell executes may be in the form of cmdlets, which are specialized .NET classes designed expressly to expose a functionality via PowerShell, PowerShell scripts (*.ps1) or regular executables. If a command is an executable file, PowerShell 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 basic 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 parameter value to the parameter is done by PowerShell itself, but for external executables, parameters 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 byte streams. Byte streams require the receiving command to parse them to extract the data it needs, using either the capabilities of the shell or special-purpose tools, such as grep and AWK. But when data is piped as objects, the elements they encapsulate retain their types, making them distinguishable through separate properties. The recipient cmdlet can then access the data elements by their properties without implementing a parser. An object can also encapsulate certain functions that work on the contained data. These also become available to the recipient command for use.[9][10] For the last cmdlet in a pipeline, PowerShell automatically pipes its output object to the Write-Host cmdlet, which creates a formatted text representation of its data, writing it to the screen.[11][12]

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 external executables are 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 certain extensions. 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 an XML-based language.[13]

Cmdlets

Cmdlets are specialized commands in the PowerShell environment that implement specific functions. These are the native commands in the PowerShell stack. Cmdlets follow a <verb>-<noun> naming pattern, such as Get-ChildItem, helping to make them (according to Microsoft) self-descriptive.[14] Cmdlets output their results as objects, or collections thereof (including arrays), and can optionally receive input in that form, making them suitable for use as recipients in a pipeline. But while PowerShell allows arrays and other collection of objects to be written to the pipeline, cmdlets always process objects individually. For collections of objects, PowerShell invokes the cmdlet on each object in the collection, in sequence.[14]

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.[14] 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.[15] If a collection of objects are 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[16] 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.[17]

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, and registry.[18] 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.

Scripting

Windows PowerShell includes an untyped scripting language which can implement complex operations using cmdlets imperatively. The scripting language supports variables, functions, branching (if-then-else), loops (while, do, for, and foreach), and error handling, 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; in the former case, 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.[19] 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. It provides two syntaxes for invoking a function:

  1. <function> <param1> <param2> …': In this case, the function need not define the parameters it accepts; the parameters will be passed as an array accessible from inside the function via the $args array.[20]
  2. <function>(<param1>, <param2>): In this case, the function declaration must specify the parameters it accepts, and their types. The parameters passed will be bound to the parameter variables when the function is called.[21]

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.[22] 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.[22]

For error handling, PowerShell provides .NET style Try…Catch…Finally blocks. In case of errors, objects containing errors about the error (Exception object) are thrown, which are caught using the trap. However, the action-or-error is configurable; in case of an error PowerShell can be configured to silently resume execution, without trapping the exception.[23]

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.[24] PowerShell scripts can be signed to verify their integrity, and are subject to .NET Code Access Security.

Hosting

Another use of PowerShell is being embedded in a management application, which then uses the PowerShell runtime to implement the management functionality. For this, PowerShell provides a managed hosting API. Via the APIs, the application can instantiate a runspace (one instantiation of the PowerShell runtime), which runs in the application's process and is exposed as a Runspace object.[1] 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.[1] 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.[1] Once the pipeline is setup, 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.

Public reception

Public reception of Windows PowerShell 1.0 has generally been quite positive. In his Windows Server 2008 review technology reporter Paul Thurrott states:

PowerShell is a complex but technically impressive environment, with support for discoverable .NET-based objects, properties, and methods. It provides all of the power of UNIX command line environments with none of the inconsistencies.[25]

According to Microsoft, PowerShell has had almost a million downloads in its first six months. [26] There is also a growing list of products that are shipping with PowerShell support.

PowerShell 2.0

Template:Future software

Graphical PowerShell, with multiple open RunSpaces and the GridView window

Microsoft is working on the next version of PowerShell and has made a CTP release of the same publicly available. It includes changes to the scripting language and hosting API, in addition to including a number of cmdlets. A non-exhaustive list of the new features is:[27]

  1. PowerShell Remoting: Using WS-Management, PowerShell 2.0 allows scripts and cmdlets to be invoked on a remote machine or a large set of remote machines.
  2. Background Jobs: Also called a PSJob, it allows a command sequence (script) or pipeline to be invoked asynchronously. Jobs can be run on the local machine or on multiple remote machines. A PSJob cannot include interactive cmdlets.
  3. ScriptCmdlets: These are cmdlets written using the PowerShell scripting language.
  4. SteppablePipelines: This allows the user to control when the BeginProcessing(), ProcessRecord() and EndProcessing() functions of a cmdlet are called.
  5. Data Language: A domain-specific subset of the PowerShell scripting language, that allows data definitions to be decoupled from the scripts and allow localized string resources to be imported into the script at runtime.
  6. Script Debugging: It allows breakpoints to be set in a PowerShell script or function. Breakpoints can be set on lines, line & columns, commands and read or write access of variables. It includes a set of cmdlets to control the breakpoints via script.
  7. New Cmdlets: Including Out-GridView, which displays tabular data in the WPF GridView object.
  8. New Operators: -Split -Join and @ operators.
  9. New APIs: The new APIs range from handing more control over the PowerShell parser and runtime to the host, to creating and managing collection of Runspaces (Runspace Pools) as well as the ability to create restricted Runspaces which only allow a configured subset of PowerShell to be invoked.
  10. Graphical PowerShell: PowerShell 2.0 includes a GUI-based PowerShell host that provides integrated debugger, syntax highlighting and up to 8 PowerShell consoles (Runspaces) in a tabbed UI, as well as to run only the selected parts in a script.. However, it is a very early release which suffers from performance problems with large scripts and does not include tab completion.

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-Location sl, cd, chdir cd, chdir cd Change the current directory
Clear-Host cls, clear cls clear Clear the screen
Copy-Item cpi, copy, cp copy cp Copy one or several files / a whole directory tree
Get-Help help, man help man Help on commands
Remove-Item ri, del, rmdir, rd, rm del, rmdir, rd rm, rmdir Delete a file / a directory
Rename-Item rni, ren ren mv Rename a file / a directory
Get-ChildItem gci, dir, ls dir ls List all files / directories in the (current) directory
Write-Output echo, write echo echo Print strings, variables etc. to standard output
Pop-Location popd popd popd Change the current directory to the directory most recently pushed onto the stack
Push-Location pushd pushd pushd Push the current directory onto the stack
Set-Variable sv, set set set Set the value of a variable / create a variable
Get-Content gc, type, cat type cat Get the content of a file
Get-Process gps, ps tlist[28], tasklist[29] ps List all currently running processes
Stop-Process spps, kill kill[28], taskkill[29] kill Stop a running process
Tee-Object tee ? tee Pipe input to a file or variable, then pass the input along the pipeline

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

Application support

Application Version Cmdlets Provider Management GUI
Exchange Server 2007 Yes Yes Yes
Windows Server 2008 Yes Yes No
Microsoft SQL Server 2008 Yes Yes No
System Center Operations Manager 2007 Yes Yes No
System Center Virtual Machine Manager 2007 Yes Yes Yes
System Center Data Protection Manager 2007 Yes No No
Windows Compute Cluster Server 2007 Yes Yes No
Microsoft Transporter Suite for Lotus Domino[30] 08.02.0012 Yes No No
IBM WebSphere MQ[31] 6.0.2.2 Yes No No
Quest Management Shell for Active Directory[32] 1.0.5 Yes No No
Special Operations Software Specops Command[33] 1.0 Yes No Yes

See also

References

  1. ^ a b c d e "How Windows PowerShell works". MSDN. Retrieved 2007-11-27.
  2. ^ "Extend Windows PowerShell With Custom Commands". MSDN. Retrieved 2007-11-27.
  3. ^ "Exchange 2007: Get used to the command line". Tech Republic. Retrieved 2007-11-28.
  4. ^ "SQL Server Support for PowerShell!". Retrieved 2007-11-28.
  5. ^ Dragan, Richard V. (April 23 2003). "Windows Server 2003 Delivers Improvements All Around". PC Magazine. Retrieved 2007-11-02. A standout feature here is that virtually all admin utilities now work from the command line (and most are available through telnet). {{cite web}}: Check date values in: |date= (help)
  6. ^ Snover, Jeffrey (April 25 2006). "Windows PowerShell (Monad) Has Arrived". Windows PowerShell team blog. MSDN. Retrieved 2006-04-26. {{cite web}}: Check date values in: |year= (help)CS1 maint: year (link)
  7. ^ Snover, Jeffrey (November 15 2006). "Windows PowerShell : Windows PowerShell & Windows Vista". Windows PowerShell team blog. MSDN. Retrieved 2007-01-26. {{cite web}}: Check date values in: |year= (help)CS1 maint: year (link)
  8. ^ Hansen, Kenneth (November 6 2007). "The Community Technology Preview (CTP) of Windows PowerShell 2.0". Windows PowerShell team blog. MSDN. Retrieved 2007-11-06. {{cite web}}: Check date values in: |year= (help)CS1 maint: year (link)
  9. ^ "Rethinking the Pipeline". Retrieved 2007-11-28.
  10. ^ "Windows PowerShell Object Concepts". Retrieved 2007-11-28.
  11. ^ "How PowerShell Formatting and Outputting REALLY works". Retrieved 2007-11-28.
  12. ^ "More - How does PowerShell formatting really work?". Retrieved 2007-11-28.
  13. ^ "Windows PowerShell Extended Type System". Retrieved 2007-11-28.
  14. ^ a b c "Windows PowerShell Cmdlets". Retrieved 2007-11-28.
  15. ^ "Creating Your First Cmdlet". Retrieved 2007-11-28.
  16. ^ "Adding parameters That Process Command Line Input". Retrieved 2007-11-28.
  17. ^ "Adding parameters That Process Pipeline Input". Retrieved 2007-11-28.
  18. ^ "Windows PowerShell Providers". Retrieved 2007-11-28.
  19. ^ "Introduction to Windows PowerShell's Variables". Retrieved 2007-11-28.
  20. ^ "Functions in PowerShell". Retrieved 2007-11-28.
  21. ^ "Calling a Function with Parameters". Retrieved 2007-11-28.
  22. ^ a b "Lightweight Testing with Windows PowerShell". Retrieved 2007-11-28.
  23. ^ "Trap [Exception] { "In PowerShell" }". Retrieved 2007-11-28.
  24. ^ "Running Windows PowerShell Scripts". Retrieved 2007-11-28.
  25. ^ Windows Server 2008 Review
  26. ^ PowerShell Hits a Million Downloads in the First Six Months
  27. ^ "What's New in CTP of PowerShell 2.0". Retrieved 2007-11-28.
  28. ^ a b Available in Windows NT4, Windows 98 Resource Kit, Windows 2000 Support Tools
  29. ^ a b Available in Windows XP Professional Edition and later
  30. ^ "Microsoft Transporter Suite for Lotus Domino". Retrieved 2008-03-07.
  31. ^ "MO74: WebSphere MQ - Windows Powershell Library". Retrieved 2007-12-05.
  32. ^ "PowerShell Commands for Active Directory Quest Software". Retrieved 2007-12-05.
  33. ^ "PowerShell Remoting through Group Policy". Retrieved 2007-12-07.

Books

3rd-party tools

PowerShell providers