Set-Item
SYNOPSIS
Changes the value of an item to the value specified in the command.
SYNTAX
Set-Item [-path] <string[]> [[-value] <Object>] [-force] [-include <string[]>] [-exclude <string[]>] [-filter <string>] [-passThru] [-credential <PSCredential>] [-whatIf] [-confirm] [<CommonParameters>]
Set-Item [-literalPath] <string[]> [[-value] <Object>] [-force] [-include <string[]>] [-exclude <string[]>] [-filter <string>] [-passThru] [-credential <PSCredential>] [-whatIf] [-confirm] [<CommonParameters>]
DETAILED DESCRIPTION
The Set-Item cmdlet changes the value of an item, such as a variable or registry key, to the value specified in the command.
PARAMETERS
-path <string[]>
Specifies a path to the location of the new items. Wildcards are permitted.
Required? |
true |
Position? |
1 |
Default value |
N/A - The Path must be specified |
Accept pipeline input? |
true (ByPropertyName) |
Accept wildcard characters? |
true |
-value <Object>
Specifies a new value for the item.
Required? |
false |
Position? |
2 |
Default value |
<Provider specific> |
Accept pipeline input? |
true (ByValue, ByPropertyName) |
Accept wildcard characters? |
false |
-force <SwitchParameter>
Overrides restrictions that prevent the command from succeeding, just so the changes do not compromise security. For example, Force will override the read-only attribute or create directories to complete a file path, but it will not attempt to change file permissions.
Required? |
false |
Position? |
named |
Default value |
False |
Accept pipeline input? |
false |
Accept wildcard characters? |
false |
-include <string[]>
Changes only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted.
Required? |
false |
Position? |
named |
Default value |
|
Accept pipeline input? |
false |
Accept wildcard characters? |
true |
-exclude <string[]>
Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted.
Required? |
false |
Position? |
named |
Default value |
|
Accept pipeline input? |
false |
Accept wildcard characters? |
true |
-filter <string>
Specifies a filter in the provider's format or language. The value of this parameter qualifies the Path parameter. The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved.
Required? |
false |
Position? |
named |
Default value |
|
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 |
-credential <PSCredential>
Uses a credential to validate access to the file. <Credential> represents a user-name, such as "User01" or "Domain01\User01", or a PSCredential object, such as the one retrieved by using the Get-Credential cmdlet. If you type a user name, you will be prompted for a password. This parameter appears, but it is not supported in any Windows PowerShell core cmdlets or providers.
Required? |
false |
Position? |
named |
Default value |
|
Accept pipeline input? |
true (ByPropertyName) |
Accept wildcard characters? |
false |
-literalPath <string[]>
Specifies a path to the location of the new items. Unlike Path, the value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.
Required? |
true |
Position? |
1 |
Default value |
|
Accept pipeline input? |
true (ByPropertyName) |
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>
This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".
INPUT TYPE
Any
NOTES
For more information, type "Get-Help Set-Item -detailed". For technical information, type "Get-Help Set-Item -full".
The Set-Item cmdlet is not supported by the Windows PowerShell FileSystem provider. To change the values of items in the file system, use Set-Content.
In the Registry drives, HKLM: and HKCU:, Set-Item changes the data in the (Default) value of a registry key. To create and changes the names of registry keys, use New-Itemand Rename-Item. To change the names and data in registry values, use New-ItemProperty, Set-ItemProperty, and Rename-ItemProperty.
When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".
You can also refer to Set-Item by its built-in alias, "si". For more information, see About_Alias.
EXAMPLE 1
set-item -path alias:np -value c:\windows\notepad.exe
This command creates an alias of "np" for Notepad.
EXAMPLE 2
set-item -path env:UserRole -value Administrator
This command uses the Set-Item cmdlet to change the value of the "UserRole" environment variable to "Administrator"
.
EXAMPLE 3
set-item -path function:prompt -value {'PS '+ $(Get-Date -format t) + " " + $(Get-Location) + '> '}
This command uses the Set-Item cmdlet to change the "prompt" function so that it displays the time before the path.
EXAMPLE 4
set-item -path function:prompt -options "AllScope,ReadOnly"
This command sets the AllScope and ReadOnly options for the "prompt" function. This command uses the Options dynamic parameter of the Set-Item cmdlet. The Options parameter is available in Set-Item only when you use it with the Alias or Function provider.
RELATED LINKS