You are here:

WindowsManagement.com > PowerShell > PowerShell 1.0 > New-Variable
ActiveXperts Network Monitor 2015 proactively manages network servers, devices, databases and more.

New-Variable - PowerShell 1.0

Microsoft Windows PowerShell is a command-line shell and scripting tool based on the Microsoft .NET Framework. It is designed for system administrators, engineers and developers to control and automate the administration of Windows and applications.

More than hundred command-line tools (so called "cmdlets") can be used to perform system administration tasks and Windows Management Instrumentation (WMI). These cmdlets are easy to use, with standard naming conventions and common parameters, and standard tools for piping, sorting, filtering, and formatting data and objects.

New-Variable


Description
Back up your Hyper-V VMs Easy & Fast. 100% built for Hyper-V. Free for 2 VMs, forever.

Usage


Options
-Name 
       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.

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

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

Example(s)
Create a new variable:

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

Create a new variable and assign a value:

PS C:\>new-variable zipcode -value 90210
"$zipcode"
# Now change the value
$zipcode=54398
"$zipcode"