TOPIC
    about_Operators

SHORT DESCRIPTION
    Describes the operators that are supported by Windows PowerShell. 

LONG DESCRIPTION
    An operator is a language element that you can use in a command or
    expression. Windows PowerShell supports several types of operators to
    help you manipulate values.


  Arithmetic Operators
      Use arithmetic operators (+, -, *, /, %) to calculate values in a command
      or expression. With these operators, you can add, subtract, multiply, or
      divide values, and calculate the remainder (modulus) of a division 
      operation.


      You can also use arithmetic operators with strings, arrays, and hash 
      tables. The addition operator concatenates elements. The multiplication
      operator returns the specified number of copies of each element.


      For more information, see about_Arithmetic_Operators. 


  Assignment Operators
      Use assignment operators (=, +=, -=, *=, /=, %=) to assign one or more
      values to variables, to change the values in a variable, and to append
      values to variables. You can also cast the variable as any Microsoft .NET
      Framework data type, such as string or DateTime, or Process variable.


      For more information, see about_Assignment_Operators.


  Comparison Operators
      Use comparison operators (-eq, -ne, -gt, -lt, -le, -ge) to compare values
      and test conditions. For example, you can compare two string values to 
      determine whether they are equal. 


      The comparison operators include the match operators (-match, -notmatch) 
      to find patterns using regular expressions; the replace operator 
      (-replace), which uses regular expressions to change input values; and 
      the like operators (-like, -notlike), which find patterns using wildcard 
      characters (*). 


      They also include the bitwise operators (-bAND, -bOR, -bXOR, -bNOT) to 
      manipulate the bit patterns in values.


    For more information, see about_Comparison_Operators 


  Logical Operators
      Use logical operators (-and, -or, -xor, -not, !) to connect conditional
      statements into a single complex conditional. For example, you can use a
      logical -and operator to create an object filter with two different 
      conditions.


      For more information, see about_Logical_Operators.


  Redirection Operators
      Use redirection operators (>, >>, 2>, 2>, and 2>&1) to send the output of
      a command or expression to a text file. The redirection operators work 
      like the Out-File cmdlet (without parameters) but they also let you 
      redirect error output to specified files. You can also use the Tee-Object
      cmdlet to redirect output.


      For more information, see about_Redirection.


  Split and Join Operators
      The -split and -join operators divide and combine substrings. The -split 
      operator splits a string into substrings. The -join operator concatenates
      multiple strings into a single string.


      For more information, see about_Split and about_Join.


  Type Operators
      Use the type operators (-is, -isnot, -as) to find or change the .NET 
      Framework type of an object. 

      For more information, see about_Type_Operators.


  Unary Operators
      Use unary operators to increment or decrement variables or object 
      properties and to set integers to positive or negative numbers. For 
      example, to increment the variable $a from 9 to 10, you type $a++.


  Special Operators
      Use special operators to perform tasks that cannot be performed by the 
      other types of operators. For example, special operators allow you to 
      perform operations such as running commands and changing a value's data 
      type.

    
      &  Call operator
        Description: Runs a command, script, or script block. Because the call 
        operator does not parse, it cannot interpret command parameters. The 
        call operator, also known as the "invocation operator, indicates that 
        the value it precedes is a command. This enables you to run commands 
        stored in variables and represented by strings. Examples:


            & "new cmdlet"
            $c = "get-executionpolicy"    
            & $c


      . Property dereference operator
        Description: Accesses the properties and methods of an object. 
        Examples:


            $myString.length
            $myString.substring(1,3)


      . dot sourcing operator
        Description: Runs a script so that the items in the script are part 
        of the calling scope. For more information, see about_Scope. Example:


            . c:\scripts.sample.ps1


        Note: The dot (.) symbol is also used as the parent directory symbol, 
              as in this example:

                .\sample.ps1

              This command runs the sample.ps1 script, but not as part of the 
              calling scope.


      :: Static member operator
        Description: Calls the static properties operator and methods of a .NET
        Framework class. To find the static properties and methods of an 
        object, use the Static parameter of the Get-Member cmdlet. Example:


            [datetime]::now
 

      .. Range operator
        Description: Represents the sequential integers in an integer array, 
        given an upper and lower boundary. Examples:


            1..10
            10..1
            foreach ($a in 1..$max) {write-host $a}


      -f Format operator
        Description: Formats strings by using the format method of string 
        objects. Enter the format string on the left side of the operator 
        and the objects to be formatted on the right side of the operator.
        Examples:


            C:\PS> "{0} {1,-10} {2:N}" -f 
            C:\PS> 1,"hello",[math]::pi
            1 hello 3.14


      $( ) Subexpression operator
        Description: Returns the result of one or more statements. For a 
        single result, returns a scalar. For multiple results, returns an 
        array. Examples:


            $($x * 23)
            $(Get-WMIObject win32_Directory)


      @( ) Array subexpression operator
        Description: Returns the result of one or more statements as an array. 
        If there is only one item, the array has only one member. Example:


            @(Get-WMIObject win32_logicalDisk)
                       

      , operator
        Description: As a binary operator, the comma creates an array. As a 
        unary operator, the comma creates an array with one member. Place the
        comma before the member. Examples:


            $myArray = 1,2,3 
            $SingleArray = ,1     

       
SEE ALSO
    about_Arithmetic_Operators
    about_Assignment_Operators
    about_Comparison_Operators
    about_Logical_Operators
    about_Type_Operators
    about_Split
    about_Join
    about_Redirection




Table Of Contents