Windows PowerShell

The Windows PowerShell ( powershell.exe ), sometimes also known under the code name Monad and Microsoft Command Shell ( MSH ) is a technology developed by Microsoft alternative to the Windows command line program cmd.exe and Windows Script Host.

Purpose and characteristics

Built on the. NET Framework version 2.0 Windows PowerShell combines the familiar from Unix shells philosophy of pipes and filters with the paradigm of object-oriented programming. The user can execute simple commands as before to a command line and combine with one another or even complex script programs with the specially developed PowerShell Scripting Language Review.

Originally, the first release of PowerShell was planned as part of Windows Vista on 30 November 2006. However, it was only supplied with the Microsoft Exchange Server 2007 published simultaneously. On all subsequent PC operating systems from Microsoft PowerShell is already installed.

Versions 1.0 and 2.0 are also available for the operating systems Windows XP, Windows Server 2003 and Windows Vista for free download.

Starting with Windows 7, PowerShell is installed in version 2.0. It contains, among other things, the graphical development environment PowerShell ISE (Integrated Scripting Environment ). It supports AutoComplete commands, syntax color markings and includes a script debugger.

Windows 8 comes with version 3.0 of PowerShell. Key changes it brings support for workflows based on the Windows Workflow Foundation, remote sessions that are interrupted or later can be resumed from another PC, and the possibility of time-controlled or dependent on events run scripts. PowerShell 3.0 is included as part of the Windows Management Framework 3.0 for Windows 7 SP1 and Windows Server 2008 R2 SP1 available; for XP and Vista does not.

The Management Framework 4.0 for Windows 7 SP1 and Windows Server 2008 R2 SP1 was released on 24 October 2013 as the final version. It ships with Windows Server 2012 R2, and Windows 8.1 by default.

Details

The core of the PowerShell form small functional units, called cmdlets (pronounced command-lets ), which follow the naming scheme verb-noun, so, for example, the Get-Help Set-Location or, where the case does not matter. As the titles of some cmdlets are relatively long, shorter alias names can be assigned, some of which have are predefined by default, including as an aid for migrating from Unix shells or the DOS / NT command line ( for example, ls, dir, cp, ... ). PowerShell 2.0 includes cmdlets 236 and 137 aliases.

The cmdlets are implemented as special NET classes, which (as indicated by a preceding " -") as input certain parameters. , And objects take and return as output, in turn, objects that then output formatted as a table or for further processing to other cmdlets forwarded can be. Since the issue does not occur as a text stream, but as a structured object, certain properties can easily select and manipulate text without complex analysis. However, analyzes of Regular expressions are also possible. Returned objects can also be stored in variables and re-used elsewhere.

The functionality of PowerShell can be extended by so-called snap-ins, which import all in one fell swoop sets of cmdlets and make available to the user. Using Get-Help cmdlet help pages are displayed, which are similar to the format of Unix man pages. If cmdlets are called with the special parameter "- whatif ", the user is informed of what had happened, but an action does not take place.

In addition to cmdlets can be directly from the command line and conventional programs, user-defined functions, scripts and batch files to start, as documents that are opened when the associated application program.

The PowerShell provides access to WMI classes, COM objects as well as to the whole. NET Framework.

So called provider hierarchical structures such as the Windows registry database, the variable namespace and others as virtual drives can be integrated and how a file system to navigate, are referenced and edited, for example, " Env :", " HKLM ", " variable " or "Function ". However, these are not displayed in Windows Explorer.

In the interactive mode, the PowerShell provides automatic tab-completion by TAB for cmdlets, parameters, properties, and file and directory names that can be adjusted as needed by the user to his own needs.

Unlike previously existing object- oriented scripting interpreter ( BeanShell, Smalltalk, Python Shell) is the syntax of the PowerShell scripting language that takes, among other bonds in Perl, Unix shells, SQL and C #, designed for daily interactive use to be suitable as a shell for administrative tasks such as file management.

Cmdlets

Cmdlets are in a. NET language extensions written for PowerShell. In addition, it is possible to write scripts in the PowerShell scripting language, such as the cmdlets behave. The following table shows a selection of the included cmdlets up over the previous commands in other command line interpreter.

Verbs

The verbs that are used cmdlets can start, can be classified into groups: The list of possible verbs depends on the PowerShell version used and can be retrieved using the Get- Verb.

Although other verbs such as checkout and commit are possible, but not allowed. Instead, the standard such as verbs and submit request to be used. However, other verbs can be defined in the form of an alias. In order to list cmdlets with certain verbs of command Get-Command -Verb be used .

Snap -ins

Cmdlets are summarized in a snap-in. Snap- ins are installed with InstallUtil.exe AssemblyName.dll, which is a part of. NET framework. Installed snap- ins can be activated with Add- PSSnapin then. Active snap-ins can be listed with Get- PSSnapin or Get- PSSnapin -Registered and removed with the Remove- PSSnapin.

A snap-in in C # looks like this:

PowerShell scripts are dynamically typed. Here, an extended type system comes (English: extended type system, ETS) used to be encapsulated in the NET objects in the PSObject class.. PSObject here represents the base class for PowerShell objects dar.

Using System; using System.Management.Automation;   namespace PowerShell {      public class PSObjectExample      {          public void Main ()          {              var time = DateTime.UtcNow;              var time = new PSObject power (time);          }       } } In PowerShell: $ time = [ System.DateTime ] :: UtcNow $ time = power [ System.Management.Automation.PSObject ] $ time PowerShell provides implicit type conversion. This type converters are used, some of which are predefined:

Provider

Providers are PowerShell snap-ins, which, for example, access to hierarchical data ( NavigationCmdletProvider ) or key - value pairs ( ContainerCmdletProvider ) allow. Depending on the type of the provider a certain amount of cmdlets is provided. The active providers can be accessed using the Get - PSProvider command.

Modules

Functions, type definitions, snap-ins, cmdlets and providers can be combined into one module. The environment variable $ env: PSModulePath points to the directories where the PowerShell console for modules seeks to integrate this at startup automatically.

Modules are not installed with InstallUtil.exe, but only copied to the appropriate directory. The commands to manage modules obtained with Get-Command * modules *.

Examples

Give the string " Hello world!" on the console:

Write-Host "Hello world! " Finish all processes whose names begin with the letter " p":

Get-process p * | Stop-Process Find all processes that use more than 10 MB of memory, and finish it:

Get-Process | where { $ _.WS -gt 10MB } | Stop-Process Calculate the total number of bytes of all files in a directory:

Get- ChildItem | Measure-Object - Property Length - Sum Wait until a certain process has been completed:

$ processToWatch = Get-Process notepad    $ processToWatch.WaitForExit () Change a string from lowercase to uppercase:

" hello world ". ToUpper () Add the string "ABC" by the first letter of the word "string" to get the result " sABCtring ":

"string". Insert ( 1, "ABC" ) Loading a particular RSS feed now and show the headings of the eight latest entries:

$ RSSURL = " http://blogs.msdn.com/b/powershell/rss.aspx "    $ blog = [xml ] ( new-object System.Net.WebClient ). DownloadString ($ RSSURL )    $ blog.rss.channel.item | select title -first 8 Erase the entire hard drive without a prompt, equivalent to rm- rf / Unix:

  • . ps1 - Windows PowerShell shell script
  • . ps1xml - Windows PowerShell format and type definitions
  • . psc1 - Windows PowerShell console file (exported shell configuration)
  • . psd1 - Windows PowerShell data file
  • . psm1 - Windows PowerShell module file

Software support

Among others, the following systems are supported:

Swell

322483
de