Set-Variable
SYNOPSIS
Sets the value of a variable. Creates the variable if one with the requested name does not exist.
SYNTAX
Set-Variable [-name] <string[]> [[-value] <Object>] [-include <string[]>] [-exclude <string[]>] [-scope <string>] [-description <string>] [-option {<None> | <ReadOnly> | <Constant> | <Private> | <AllScope>}] [-force] [-passThru] [-whatIf] [-confirm] [<CommonParameters>]
DETAILED DESCRIPTION
Sets the value of a variable. May create the variable if one with the requested name does not exist.
PARAMETERS
-name <string[]>
Specifies the variable name.
Required? |
true |
Position? |
1 |
Default value |
N/A - The Name must be specified |
Accept pipeline input? |
true (ByPropertyName) |
Accept wildcard characters? |
true |
-include <string[]>
Specifies only those items upon which the cmdlet will act, excluding all others.
Required? |
false |
Position? |
named |
Default value |
|
Accept pipeline input? |
false |
Accept wildcard characters? |
true |
-exclude <string[]>
Specifies those items upon which the cmdlet will not to act and include all others.
Required? |
false |
Position? |
named |
Default value |
|
Accept pipeline input? |
false |
Accept wildcard characters? |
true |
-scope <string>
Specifies the scope from which aliases should be exported. This can be a named scope: "global", "local", or "script", or it can be a number relative to the current scope (0 through the number of scopes where 0 is the current scope and 1 is its parent).
Required? |
false |
Position? |
named |
Default value |
local |
Accept pipeline input? |
false |
Accept wildcard characters? |
false |
-value <Object>
Specifies the value to assign to the variable.
Required? |
false |
Position? |
2 |
Default value |
Null |
Accept pipeline input? |
true (ByValue, ByPropertyName) |
Accept wildcard characters? |
false |
-description <string>
Specifies the description of the variable.
Required? |
false |
Position? |
named |
Default value |
Null |
Accept pipeline input? |
false |
Accept wildcard characters? |
false |
-option <ScopedItemOptions>
Changes the value of the Options property of the variable. Valid values are:
· None: No options. (Default)
· ReadOnly: Cannot be deleted or changed without the Force parameter.
· Constant: Cannot be deleted or changed. Constant is valid only when creating a new variable. You cannot set the Constant option on an existing variable.
· Private: Visible only in the scope specified by the Scope parameter.
· AllScope: Variable is copied to all scopes that are created.
The following lists the acceptable values for this parameter:
· None
· ReadOnly
· Constant
· Private
· AllScope
Required? |
false |
Position? |
named |
Default value |
null |
Accept pipeline input? |
false |
Accept wildcard characters? |
false |
-force <SwitchParameter>
Allows cmdlet to override restrictions such as renaming existing files as long as security is not compromised. Used to force the operation to make the best attempt at setting the variable.
Required? |
false |
Position? |
named |
Default value |
False |
Accept pipeline input? |
false |
Accept wildcard characters? |
false |
-passThru <SwitchParameter>
Passes the object created by this cmdlet through the pipeline. By default, this cmdlet does not pass any objects through the pipeline.
Required? |
false |
Position? |
named |
Default value |
False |
Accept pipeline input? |
false |
Accept wildcard characters? |
false |
-whatIf
Describes what would happen if you executed the command without actually executing the command.
Required? |
false |
Position? |
named |
Default value |
|
Accept pipeline input? |
false |
Accept wildcard characters? |
false |
-confirm
Prompts you for confirmation before executing the command.
Required? |
false |
Position? |
named |
Default value |
|
Accept pipeline input? |
false |
Accept wildcard characters? |
false |
<CommonParameters>
Directory: Microsoft.Management.Automation.Core\FileSystem::C:\Ps
INPUT TYPE
String
NOTES
For more information, type "Get-Help Set-Variable -detailed". For technical information, type "Get-Help Set-Variable -full".
When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".
EXAMPLE 1
set-variable -name desc -value "a description"
get-variable -name desc
These commands set the value of the "desc" variable to "a description", and then get the value of the variable.
EXAMPLE 2
set-variable -name processes -value (Get-Process) -option constant -scope global -description "All processes" -passthru | format-list -property *
This command creates a global, read-only variable that contains all processes on the system, and then displays all properties of the variable.
The command uses the Set-Variable cmdlet to create the variable. It uses the Passthru parameter to create an object representing the new variable, and the pipeline operator (|) to pass the object to the Format-Listcmdlet. It uses the Property parameter of Format-List with a value of all (*) to display all properties of the newly created variable.
The value, "( Get-Process)", is enclosed in parentheses to insure that it is executed before being stored in the variable. Otherwise, the variable contains the words "Get-Process".
RELATED LINKS
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster@systemmanager.forsenergy.ru to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.