You are here:

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

Set-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.

Set-Variable


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

Usage


Options
-Name String
       The name of the variable(s), may be piped.

   -value Object
       The value to assign to the variable.
		
   -include string
       Items upon which Set-variable will act, excluding all others.

   -exclude string
       Items upon which Set-variable will not act, include all others.

   -option option
       The valid options are: 
         None    : Set no options. (default) 
         ReadOnly: The alias cannot be changed unless you use -Force. 
         Constant: The alias cannot be changed, even by using -Force. 
         Private : The alias is available only within the scope specified by -Scope. 
                   It is invisible in all other scopes.  
   -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".

   -force
       Override restrictions that prevent the command from succeeding, apart
       from security settings. Make the best attempt at setting the variable.

   -passThru 
       Pass the object created by this cmdlet 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.

   -description string
       The description of the variable.
		
   CommonParameters:
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.

Example(s)
Set the value of the "SS64" variable to "My Sample text ":

PS C:\>set-variable -name SS64 -value "My Sample text"

Create a global, read-only variable that contains all processes on the system:

PS C:\>set-variable -name myprocs -value (Get-Process) -option constant -scope global

In the example above, the value is enclosed in parentheses this executes the command: (Get-Process) before storing the result in the variable, rather than just storing the text "Get-Process".