,

Windows Powershell – Introduction

Here I offer the reader a bit of output from the Microsoft Windows ( .NET ) Powershell. Powershell is available for windows users to download for no cost, as a facility for interfacing with many .NET functions, as well as some typical Windows Shell (cmd.exe) functions; some interesting enhancements to the functionality of The OS and available .NET Framework components which may be able to do some heavy lifting, as its said, for the user in a fraction of the time and effort which may be required through other means.

See also:

Please note that it is for the express purpose of DEMONSTRATION ONLY, so the reader might make his or her own decisions about the subject, as this author makes no claim here regarding the quality of the software itself or the operation thereof, his fascination with the software notwithstanding. WordPress Center .net encourages you, the reader, to develop your own opinions and share your feelings in the comments below. We hot that such texts are educational, insightful, and balanced.

as output, verbatim from Windows PowerShell, the following shows a query instance of “get-help about_*”, where the last few cmdlet items are shown, then I specifiy precisely “get-help about_regular”, where Powershell was intuitive enough to display that which I wanted: more information on the available Windows .Net Powershell Regular Expression syntax

about_property             HelpFile                   Using object propertie...
about_provider             HelpFile                   Windows PowerShell pro...
about_pssnapins            HelpFile                   A Windows PowerShell s...
about_quoting_rules        HelpFile                   Rules for setting the ...
about_redirection          HelpFile                   Redirecting output fro...
about_ref                  HelpFile                   How to create and use ...
about_regular_expression   HelpFile                   Using regular expressi...
about_reserved_words       HelpFile                   Words in the Windows P...
about_scope                HelpFile                   The visibility a funct...
about_script_block         HelpFile                   Grouping statements an...
about_shell_variable       HelpFile                   Variables that are cre...
about_signing              HelpFile                   Describes the Windows ...
about_special_characters   HelpFile                   The special characters...
about_switch               HelpFile                   Using a switch to hand...
about_system_state         HelpFile                   Data maintained by the...
about_types                HelpFile                   Extending the .NET typ...
about_where                HelpFile                   Filter objects based o...
about_while                HelpFile                   A language statement f...
about_wildcard             HelpFile                   Using wildcards in Cmd...
 
 
SEE ALSO
    For information about the match comparison operator, enter the
    following command at the PowerShell command prompt:


        help about_comparison_operators


    See the MSDN Documentation on Regular Expression Language Elements


PS C:> get-help about_regular

TOPIC Regular expressions

SHORT DESCRIPTION

Using regular expressions in Cmdlet parameters in the Windows PowerShell

LONG DESCRIPTION

PowerShell supports a number of the regular expression characters:

Format Logic Example

        -------- ------------------------------- -----------------------
        value    Matches exact characters        "book" -match "oo"
                 anywhere in the original value
        .        Matches any single character    "copy" -match "c..y"
        [value]  Matches at least one of the     "big" -match "b[iou]g"
                 characters in the brackets
        [range]  Matches at least one of the     "and" -match "[a-e]nd"
                 characters within the range.
                 The Use of a hyphen (-) allows
                 specification of contiguous
                 character.
        [^]      Matches any character except    "and" -match "[^brt]nd"
                 those in brackets
        ^        Matches the beginning           "book" -match "^bo"
                 characters
        $        Matches the end characters      "book" -match "ok$"
        *        Matches zero or more instances  "baggy" -match "g*"
                 of the preceding character
        ?        Matches zero or one instance    "baggy" -match "g?"
                 of the preceding character
                Matches the character that      "Try$" -match "Try$"
                 follows as an escaped character

character classes available in .NET regular expressions

Format Logic Example

        -------- ------------------------------- -----------------------
        p{name} Matches any character in the    "abcd defg" -match "p{Ll}+"
                 named character class specified
                 by {name}. Supported names are
                 Unicode groups and block
                 ranges. For example, Ll, Nd,
                 Z, IsGreek, IsBoxDrawing.
        P{name} Matches text not included in    1234 -match "P{Ll}+"
                 groups and block ranges
                 specified in {name}.
        w       Matches any word character.     "abcd defg" -match "w+"
                 Equivalent to the Unicode       (this matches abcd)
                 character categories [p{Ll}
                 p{Lu}p{Lt}p{Lo}p{Nd}p{Pc}].
                 If ECMAScript-compliant behavior
                 is specified with the ECMAScript
                 option, w is equivalent to
                 [a-zA-Z_0-9].
        W       Matches any nonword character.  "abcd defg" -match "W+"
                 Equivalent to the Unicode       (This matches the space)
                 categories [^p{Ll}p{Lu}p{Lt}
                 p{Lo}p{Nd}p{Pc}].
        s       Matches any white-space         "abcd defg" -match "s+"
                 character.  Equivalent to the
                 Unicode character categories
                 [fnrtvx85p{Z}].
        S       Matches any non-white-space     "abcd defg" -match "S+"
                 character. Equivalent to the
                 Unicode character categories
                 [^fnrtvx85p{Z}].
        d       Matches any decimal digit.      12345 -match "d+"
                 Equivalent to p{Nd} for
                 Unicode and [0-9] for non-
                 Unicode behavior.
        D       Matches any nondigit.           "abcd" -match "D+"
                 Equivalent  to P{Nd} for
                 Unicode and [^0-9] for non-
                 Unicode behavior. 

PowerShell supports the quantifiers available in .NET regular expressions,
The following are some examples of quantifiers in Powershell:

Format Logic Example

        -------- ------------------------------- -----------------------
        *        Specifies zero or more matches; "abc" -match "w*"
                 for example, w* or (abc)*.
                 Equivalent to {0,}.
        +        Matches repeating instances of  "xyxyxy" -match "xy+"
                 the preceding characters
        ?        Specifies zero or one matches;  "abc" -match "w?"
                 for example, w? or (abc)?.
                 Equivalent to {0,1}.
        {n}      Specifies exactly n matches;    "abc" -match "w{2}"
                 for example, (pizza){2}.
        {n,}     Specifies at least n matches;   "abc" -match "w{2,}"
                 for example, (abc){2,}.
        {n,m}    Specifies at least n, but no    "abc" -match "w{2,3}"
                 more than m, matches.


    All of the comparisons shown in the table above evaluate to true.

Note that the escape character for regular expressions is different than that of the PowerShell. The character escape for regular expressions is the backslash{1}.

{1}Backslash, aka. Reverse Solidus: [ U+005C ] :
Note. Whenever you see a Unicode character represented as such (e.g. usually leading zeros in an alphanumeric sequence of 2-6 numbers), if a visible character exists for that code, that character can be represented as a Numerical Character Reference by replacing the “U+” part with &#x (“amp-hash-X”/ “amp-pound-X”), the-code (5C here because we can omit leading zeros) and a semi-colon [ ; ] indicates the end of the NCR so &#x 5c ; is rendered as \

SEE ALSO
For information about the match comparison operator, enter the
following command at the PowerShell command prompt:

help about_comparison_operators

See the MSDN Documentation on Regular Expression Language Elements

Powershell is a Microsoft .NET thing which means so it’s also related to C# (the relative minor of E major). Any time you get to learn something from Hey Scripting Guy is also a bonus! Maybe it’s time to take Shia LaBeouf’s advice: “Do it!”


Leave a Reply

Your email address will not be published. Required fields are marked *