< Back

Set-Item

Tue Jan 29, 2019 10:20 pm

NAME Set-Item



SYNOPSIS

Changes the value of an item to the value specified in the command.





SYNTAX

Set-Item [[-Value] <Object>] [-Confirm] [-Credential <PSCredential>] [-Exclude <String[]>] [-Filter <String>] [-Force] [-Include <String[]>]

-LiteralPath <String[]> [-PassThru] [-UseTransaction] [-WhatIf] [<CommonParameters>]



Set-Item [-Path] <String[]> [[-Value] <Object>] [-Confirm] [-Credential <PSCredential>] [-Exclude <String[]>] [-Filter <String>] [-Force]

[-Include <String[]>] [-PassThru] [-UseTransaction] [-WhatIf] [<CommonParameters>]





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

-Confirm [<SwitchParameter>]

Prompts you for confirmation before running the cmdlet.



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-Credential <PSCredential>

Specifies a user account that has permission to perform this action. The default is the current user.



Type a user name, such as User01 or Domain01\\User01, or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If

you type a user name, this cmdlet prompts for a password.



This parameter is not supported by any providers installed with parameter is not supported by any providers installed with Windows PowerShell.



Required? false

Position? named

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-Exclude <String[]>

Specifies items that this cmdlet omits. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as

*.txt. Wildcard characters are permitted.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Filter <String>

Specifies a filter in the format or language of the provider. The value of this parameter qualifies the Path parameter. The syntax of the

filter, including the use of wildcard characters, depends on the provider. Filters are more efficient than other parameters, because the

provider applies them when it retrieves the objects, instead of having Windows PowerShell filter the objects after they are retrieved.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Force [<SwitchParameter>]

Forces the cmdlet to set items that cannot otherwise be changed, such as read-only alias or variables. The cmdlet cannot change constant

aliases or variables. Implementation varies from provider to provider. For more information, see about_Providers. Even using the Force

parameter, the cmdlet cannot override security restrictions.



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-Include <String[]>

Specifies items that this cmdlet changes. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as

*.txt. Wildcard characters are permitted.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-LiteralPath <String[]>

Specifies a path of the location of the new items. Unlike Path , the value of LiteralPath is used exactly as it is typed. No characters are

interpreted as wildcard characters. 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? named

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-PassThru [<SwitchParameter>]

Passes an object that represents the item to the pipeline. By default, this cmdlet does not generate any output.



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-Path <String[]>

Specifies a path of the location of the new items. Wildcard characters are permitted.



Required? true

Position? 0

Default value None

Accept pipeline input? True (ByPropertyName)

Accept wildcard characters? false



-UseTransaction [<SwitchParameter>]

Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see

Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-Value <Object>

Specifies a new value for the item.



Required? false

Position? 1

Default value None

Accept pipeline input? True (ByPropertyName, ByValue)

Accept wildcard characters? false



-WhatIf [<SwitchParameter>]

Shows what would happen if the cmdlet runs. The cmdlet is not run.



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

System.Object

You can pipe an object that represents the new value of the item to this cmdlet.





OUTPUTS

None or an object representing the new or changed item.

This cmdlet generates an object that represent the item, if you specify the PassThru parameter. Otherwise, this cmdlet does not generate any

output.





NOTES





You can also refer to Set-Item by its built-in alias, si *. For more information, see about_Aliases. Set-Item is not supported by the Windows

PowerShell FileSystem provider. To change the values of items in the file system, use the Set-Content cmdlet.



In the Registry drives, HKLM: and HKCU:, Set-Item changes the data in the (Default) value of a registry key. To create and change the names of

registry keys, use the New-Item and Rename-Item cmdlet. To change the names and data in registry values, use the New-ItemProperty,

Set-ItemProperty, and Rename-ItemProperty cmdlets. Set-Item is designed to work with the data exposed by any provider. To list the providers

available in your session, type `Get-PsProvider`. For more information, see about_Providers.



*



Example 1: Create an alias



PS C:\\>Set-Item -Path alias:np -Value "c:\\windows\\notepad.exe"



This command creates an alias of np for Notepad.

Example 2: Change the value of an environment variable



PS C:\\>Set-Item -Path env:UserRole -Value "Administrator"



This command changes the value of the UserRole environment variable to Administrator.

Example 3: Modify your prompt function



PS C:\\>Set-Item -Path function:prompt -Value {'PS '+ $(Get-Date -Format t) + " " + $(Get-Location) + '> '}



This command changes the prompt function so that it displays the time before the path.

Example 4: Set options for your prompt function



PS C:\\>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 Set-Item . The

Options parameter is available in Set-Item only when you use it with the Alias or Function provider.



RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/?LinkId=821630

Clear-Item

Copy-Item

Get-Item

Invoke-Item

Move-Item

New-Item

Remove-Item

Rename-Item