Contact Info

Crumbtrail » Administration » Powershell » Powershell 1.0 » New-Variable

New-Variable - Powershell 1.0 CmdLet

ActiveXperts Network Monitor ships with integrated Powershell scripts to monitor complex network. The scripts run out of the box
Download the ActiveXperts Network Monitor FREE version now »


Create a new variable

New-Variable [-Name] String [[-value] Object]
           [-scope string] [-description string] 
              [-option {None | ReadOnly | Constant | Private | AllScope}]
                 [-force] [-passThru] [-whatIf] [-confirm]

       The name of the new variable(s).

   -value Object
       The value to assign to the variable, may be piped.
   -scope string
       The scope in which this alias is valid. 
       Valid values are "Global", "Local", "Private" or "Script", or a number 
       relative to the current scope ( 0 through the number of scopes, where 
       0 is the current scope and 1 is its parent). "Local" is the default.
       For more, type "get-help about_scope".

   -description string
       A description of the variable

   -option ScopedItemOptions
       Where the new variable should be visible/changeable:
       ReadOnly, Constant, Private or AllScope.

       Override restrictions as long as security is not compromised.
       Make a best attempt at setting the variable.

       Pass the object through the pipeline. By default, New-Variable 
       does not pass any objects through the pipeline.
       Describe what would happen if you executed the command without
       actually executing the command.
       Prompt for confirmation before executing the command.
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.

Create a new variable:

PS C:\>new-variable week_day
set-variable week_day monday

Create a new variable and assign a value:

PS C:\>new-variable zipcode -value 90210
# Now change the value