
Part I: PowerShell for Exchange Fundamentals
48
Using Variables, Aliases, and Functions
Windows PowerShell provides the ability to create user - defined command elements and store them in
memory to make entering and running commands easier.
Variables
Windows PowerShell variables are basically named objects that you can use later in another command.
Variable names begin with the
$ character followed by any combination of alphanumeric characters. To
create a variable simply enter the name at the command line. The variable is created but no value is
assigned. To assign a value to a variable, enter the name followed by the equality symbol (
= ) and the
value. The value can be a literal value such as an integer or string value, or it can be the results of a
cmdlet. For example, to create a variable called
$exservers and assign it the value of all Exchange
servers in the organization, use the following command:
[PS] C:\ > $exservers = Get-ExchangeServer
Notice there is no feedback to indicate the command completed successfully. There is no feedback unless
the command fails. To see the values stored in the variable, simply enter the name:
[PS] C:\ > $exservers
Name Site ServerRole Edition AdminDisplayVe
rsion
---- ---- ---------- ------- --------------
MB001 Default-First-Sit... Mailbox,... Standard... Version 8.0...
Typing the name of the variable $exservers results in the ...