Javatpoint Logo
Javatpoint Logo

PowerShell Set-Item

The PowerShell Set-Item cmdlet changes the value of an item to the value specified in the command. It changes the value of a variable or registry key. The Windows PowerShell FileSystem provider does not support this cmdlet. In the registry drives, such as HKLM: and HKCU: it changes the data in the default value of the registry key.

Syntax


Parameters

-Path

The -Path parameter is used to specify a path of the location of the items. Wildcard characters are accepted.

-LiteralPath

The -LiteralPath parameter is used to specify a path to one or more locations. The value of this parameter is used exactly as it is typed. If the path includes the escape characters, then enclosed it in quotation marks. No characters are interpreted as wildcards. Single quotation mark tells the Windows PowerShell that it should not interpret any characters as escape sequences.

-Force

The -Force parameter allows the cmdlet to set items that cannot be changed, such as variables or read-only alias. Even using the -Force parameter, the Set-Item cmdlet cannot override the security permission.

-PassThru

The -PassThru parameter is used to pass an object which represents the item to the pipeline. By default, set-item cmdlet doesn't generate any output.

-Filter

The -Filter parameter specifies a filter to qualify the -Path parameter. The FileSystem provider is the only PowerShell provider that supports the uses of filters. This parameter is more efficient as the provider applies the filters when the cmdlet gets the object, rather than having Powershell filters the object after they are accessed.

-Value

The -Value parameter is used to specify a new value for an item.

-Exclude

The items that this cmdlet excludes in operation are specified as a string array. The value of -Exclude parameter qualifies the -Path parameter. Enter a pattern or a path element, such as *.txt. The characters of wildcard are accepted. The -Exclude parameter is effective only when the cmdlet includes the contents of an item, such as C:\*, the wildcard character '*' is used to specify the contents of the C: directory.

-Include

The items that this cmdlet includes in the operation are specified as a string array. The value of -Include parameter qualifies the -Path parameter. Enter a pattern or a path element, such as *.txt. The characters of wildcard are permitted. It is effective only when the cmdlet includes the contents of an item, such as C:\*, the wildcard character '*' is used to specify the contents of the C: directory.

-WhatIf

The -WhatIf parameter is used to display what would happen if the cmdlet executes. The cmdlet is not run.

-Confirm

The -Confirm parameter prompts a confirmation before running the cmdlet.

<Commonparameters>

This cmdlet supports the following common parameters, and their aliases are listed in parenthesis:

  • Debug (db)
  • Verbose (vb)
  • PipelineVariable (pv)
  • ErrorAction (ea)
  • ErrorVariable (ev)
  • OutVariable (ov)
  • OutBuffer (ob)
  • WarningAction (wa)
  • WarningVariable (wv)

Examples

Example 1: To create an alias

PowerShell Set-Item

The cmdlet in this example is used to create an alias for Notepad.

Example 2: To modify the prompt function

PowerShell Set-Item

The cmdlet in this example is used to change the prompt function so that it shows the time before the path.






Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA