Windows PowerShell Language Specification
Windows PowerShell Language Specification
Version 3.0
Copyright Microsoft Corporation 2009-2012. All Rights Reserved.
Notice ? 2009-2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and Windows PowerShell are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries/regions. Other product and company names mentioned herein may be the trademarks of their respective owners.
Copyright Microsoft Corporation 2009-2012. All Rights Reserved.
Table of Contents
Contents
1. Introduction............................................................................................................................................ 1
2. Lexical Structure ..................................................................................................................................... 2
2.1 Grammars ...................................................................................................................................................... 2 2.2 Lexical analysis............................................................................................................................................... 2
2.2.1 Scripts...................................................................................................................................................... 2 2.2.2 Line terminators...................................................................................................................................... 3 2.2.3 Comments............................................................................................................................................... 3 2.2.4 White space ............................................................................................................................................ 5 2.3 Tokens............................................................................................................................................................ 5 2.3.1 Keywords................................................................................................................................................. 6 2.3.2 Variables ................................................................................................................................................. 6
2.3.2.1 User-defined variables ..................................................................................................................... 8 2.3.2.2 Automatic variables ......................................................................................................................... 8 2.3.2.3 Preference variables....................................................................................................................... 14 2.3.3 Commands ............................................................................................................................................ 17 2.3.4 Parameters............................................................................................................................................ 17 2.3.5 Literals................................................................................................................................................... 19 2.3.5.1 Numeric literals .............................................................................................................................. 19
2.3.5.1.1 Integer literals.......................................................................................................................... 19 2.3.5.1.2 Real literals .............................................................................................................................. 21 2.3.5.1.3 Multiplier suffixes .................................................................................................................... 22 2.3.5.2 String literals .................................................................................................................................. 22 2.3.5.3 Null literal ....................................................................................................................................... 28 2.3.5.4 Boolean literals............................................................................................................................... 28 2.3.5.5 Array literals ................................................................................................................................... 28 2.3.5.6 Hash literals.................................................................................................................................... 28 2.3.5.7 Type names .................................................................................................................................... 28 2.3.6 Operators and punctuators .................................................................................................................. 28 2.3.7 Escaped characters ............................................................................................................................... 30
3. Basic concepts........................................................................................................................................31
3.1 Providers and drives .................................................................................................................................... 31 3.1.1 Aliases ................................................................................................................................................... 32 3.1.2 Environment variables .......................................................................................................................... 32 3.1.3 File system ............................................................................................................................................ 32 3.1.4 Functions............................................................................................................................................... 33 3.1.5 Variables ............................................................................................................................................... 33
3.2 Working locations........................................................................................................................................ 33 3.3 Items ............................................................................................................................................................ 34 3.4 Path names .................................................................................................................................................. 34 3.5 Scopes.......................................................................................................................................................... 36
3.5.1 Introduction .......................................................................................................................................... 36 3.5.2 Scope names and numbers................................................................................................................... 37 3.5.3 Variable name scope............................................................................................................................. 38
Copyright Microsoft Corporation 2009-2012. All Rights Reserved.
iii
3.5.4 Function name scope............................................................................................................................ 39 3.5.5 Dot source notation .............................................................................................................................. 39 3.5.6 Modules ................................................................................................................................................ 40 3.6 ReadOnly and Constant Properties ............................................................................................................. 40 3.7 Method overloads and call resolution......................................................................................................... 40 3.7.1 Introduction .......................................................................................................................................... 40 3.7.2 Method overload resolution................................................................................................................. 41 3.7.3 Applicable method................................................................................................................................ 41 3.7.4 Better method ...................................................................................................................................... 42 3.7.5 Better conversion.................................................................................................................................. 42 3.8 Name lookup ............................................................................................................................................... 45 3.9 Type name lookup ....................................................................................................................................... 45 3.10 Automatic memory management ............................................................................................................. 45 3.11 Execution order ......................................................................................................................................... 45 3.12 Error handling ............................................................................................................................................ 45 3.13 Pipelines..................................................................................................................................................... 46 3.14 Modules ..................................................................................................................................................... 46 3.15 Wildcard expressions................................................................................................................................. 47 3.16 Regular expressions................................................................................................................................... 47
4. Types.....................................................................................................................................................50
4.1 Special types ................................................................................................................................................ 51 4.1.1 The void type....................................................................................................................................... 51 4.1.2 The null type ......................................................................................................................................... 51 4.1.3 The object type .................................................................................................................................. 51
4.2 Value types .................................................................................................................................................. 51 4.2.1 Boolean ................................................................................................................................................. 51 4.2.2 Character............................................................................................................................................... 51 4.2.3 Integer................................................................................................................................................... 52 4.2.4 Real number.......................................................................................................................................... 53 4.2.4.1 float and double ...................................................................................................................... 53 4.2.4.2 decimal ....................................................................................................................................... 54 4.2.5 The switch type .................................................................................................................................. 55 4.2.6 Enumeration types................................................................................................................................ 55 4.2.6.1 Action-Preference type .................................................................................................................. 55 4.2.6.2 Confirm-Impact type ...................................................................................................................... 55 4.2.6.3 File-Attributes type ........................................................................................................................ 56 4.2.6.4 Regular-Expression-Option type .................................................................................................... 57
4.3 Reference types ........................................................................................................................................... 57 4.3.1 Strings ................................................................................................................................................... 57 4.3.2 Arrays .................................................................................................................................................... 58 4.3.3 Hashtables............................................................................................................................................. 59 4.3.4 The xml type......................................................................................................................................... 59 4.3.5 The regex type .................................................................................................................................... 59 4.3.6 The ref type......................................................................................................................................... 59 4.3.7 The scriptblock type ....................................................................................................................... 60 4.3.8 The math type....................................................................................................................................... 61 4.3.9 The ordered type ................................................................................................................................ 63
iv
Copyright Microsoft Corporation 2009-2012. All Rights Reserved.
Table of Contents
4.3.10 The pscustomobject type............................................................................................................... 63 4.4 Generic types............................................................................................................................................... 63 4.5 Anonymous types ........................................................................................................................................ 63
4.5.1 Provider description type ..................................................................................................................... 64 4.5.2 Drive description type........................................................................................................................... 64 4.5.3 Variable description type...................................................................................................................... 64 4.5.4 Alias description type............................................................................................................................ 65 4.5.5 Working location description type ....................................................................................................... 67 4.5.6 Environment variable description type ................................................................................................ 67 4.5.7 Application description type................................................................................................................. 68 4.5.8 Cmdlet description type........................................................................................................................ 69 4.5.9 External script description type ............................................................................................................ 70 4.5.10 Function description type ................................................................................................................... 72 4.5.11 Filter description type......................................................................................................................... 74 4.5.12 Module description type..................................................................................................................... 74 4.5.13 Custom object description type.......................................................................................................... 74 4.5.14 Command description type ................................................................................................................ 74 4.5.15 Error record description type ............................................................................................................. 75 4.5.16 Enumerator description type.............................................................................................................. 75 4.5.17 Directory description type .................................................................................................................. 76 4.5.18 File description type............................................................................................................................ 77 4.5.19 Date-Time description type ................................................................................................................ 78 4.5.20 Group-Info description type ............................................................................................................... 79 4.5.21 Generic-Measure-Info description type ............................................................................................. 79 4.5.22 Text-Measure-Info description type ................................................................................................... 80 4.5.23 Credential type ................................................................................................................................... 81 4.5.24 Method designator type ..................................................................................................................... 81 4.5.25 Member definition type...................................................................................................................... 81 4.6 Type extension and adaptation ................................................................................................................... 82
5. Variables ...............................................................................................................................................84
5.1 Writable location ......................................................................................................................................... 84 5.2 Variable categories ...................................................................................................................................... 84
5.2.1 Static variables ...................................................................................................................................... 85 5.2.2 Instance variables ................................................................................................................................. 85 5.2.3 Array elements...................................................................................................................................... 85 5.2.4 Hashtable key/value pairs..................................................................................................................... 86 5.2.5 Parameters............................................................................................................................................ 86 5.2.6 Ordinary variables................................................................................................................................. 86 5.2.7 Variables on provider drives ................................................................................................................. 86 5.3 Constrained variables .................................................................................................................................. 86
6. Conversions ...........................................................................................................................................88
6.1 Conversion to void ..................................................................................................................................... 88 6.2 Conversion to bool ..................................................................................................................................... 88 6.3 Conversion to char ..................................................................................................................................... 88 6.4 Conversion to integer .................................................................................................................................. 89 6.5 Conversion to float and double ................................................................................................................... 89
Copyright Microsoft Corporation 2009-2012. All Rights Reserved.
v
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- windows powershell tutorial pdf
- administrator windows powershell ise
- open windows powershell ise x86
- windows powershell x86 commands
- what is windows powershell x86
- windows powershell vs powershell x86
- close windows powershell x86
- disable windows powershell on startup
- windows powershell robocopy
- windows powershell pip
- windows powershell startup
- windows powershell opens at startup