Store Information in Variables
1. Problem
You want to store the output of a pipeline or command for later use, or to work with it in more detail.
2. Solution
To store output for later use, store the output of the command in a variable. You can access this information later, or even pass it down the pipeline as though it was the output of the original command:
       PS >$result = 2 + 2
       PS >$result
       4
       PS >$processes = Get-Process
       PS >$processes.Count
       85
       PS >$processes | Where-Object { $_.ID -eq 0 }
       Handles NPM(K)   PM(K)     WS(K) VM(M)  CPU(s)   Id ProcessName
       ------- ------   -----     ----- -----  -----    -- -----------
            0      0       0        16    0             0 Idle
3. Discussion
Variables in PowerShell (and all other scripting and programming languages) let you store the output of something so that you can use it later. A variable name starts with a dollar sign ($) and can be followed by nearly any character. A small set of characters have special meaning to PowerShell, so PowerShell provides a way to make variable names that include even these.
You can store the result of any pipeline or command in a variable to use it later. If that command generates simple data (such as a number or string), then the variable contains simple data. If the command generates rich data (such as the objects that represent system processes from the Get-Process cmdlet), then the variable contains that list of rich data. If the command (such as a traditional executable) generates plain text (such as the output of traditional executable), then the variable contains plain text.
For more information about the syntax and types of PowerShell variables, see “Variables” in Appendix A.
In addition to variables that you create, PowerShell automatically defines several variables that represent things such as the location of your profile file, the process ID of PowerShell, and more. For a full list of these automatic variables, see Appendix C, PowerShell Automatic Variables.
Tags: info, store, variable

July 21st, 2008 at 10:06 am
Nice Site layout for your blog. I am looking forward to reading more from you.
Tom Humes