PowerShell Set-Item Cmdlet
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed Get-Item cmdlet in PowerShell.
https://cloudaffaire.com/powershell-get-item-cmdlet/
In this blog post, we will discuss Set-Item cmdlet in PowerShell. You can use Set-Item cmdlet to set an item property in a specific location. Using Set-Item cmdlet, you can set item values for variables and registry keys. Set-Item does not support filesystem providers, hence you cannot manipulate files and directories using Set-Item cmdlet. Further, Set-Item is very limited on its capability to change item property, to set all the item properties use Set-ItemProperty cmdlet.
Set-Item Cmdlet Syntax:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
## Set-Item ## [-Path] ## [[-Value] ## [-Force] ## [-PassThru] ## [-Filter ## [-Include ## [-Exclude ## [-Credential ## [-WhatIf] ## [-Confirm] ## [-UseTransaction] ## [ |
Set-Item Cmdlet Argument List:
- –Confirm: Prompts you for confirmation before running the cmdlet.
- –Credential: To impersonate another user or elevate your credentials.
- –Exclude: Specifies, as a string array, an item or items that this cmdlet excludes in the operation. The value of this parameter qualifies the Path parameter.
- –Filter: Specifies a filter to qualify the Path parameter. The FileSystem provider is the only installed PowerShell provider that supports filters.
- –Force: Forces the cmdlet to remove items that cannot otherwise be changed, such as hidden or read-only files or read-only aliases or variables.
- –Include: Specifies, as a string array, an item or items that this cmdlet includes in the operation. The value of this parameter qualifies the Path parameter.
- –LiteralPath: Specifies a path to one or more locations. The value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards.
- –PassThru: Passes an object that represents the item to the pipeline. By default, this cmdlet does not generate any output.
- –Path: Specifies a path of the items being removed. Wildcard characters are permitted.
- –UseTransaction: Includes the command in the active transaction. This parameter is valid only when a transaction is in progress.
- –Value: Specifies a new value for the item.
- –WhatIf: Shows what would happen if the cmdlet runs. The cmdlet is not run.
PowerShell Set-Item Cmdlet:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#################################### ## PowerShell | Cmdlet | Set-Item ## #################################### ## PowerShell Latest Version (5) ## create a variable, file, directory and registry key $myvar = "Hello World" New-Item -Path HKCU:\Software -Name MyRegKey -Value "Hello World" ## change item property of a variable Get-Item -Path Variable:myvar Set-Item -Path Variable:myvar "Welcome To CloudAffaire" Get-Item -Path Variable:myvar ## change item property of a registry key Get-Item -Path HKCU:\Software\MyRegKey Set-Item -Path HKCU:\Software\MyRegKey -Value "Welcome To CloudAffaire" Get-Item -Path HKCU:\Software\MyRegKey ## remove the items created for this demo Remove-Item -Path Variable:myvar Remove-Item -Path HKCU:\Software\MyRegKey |
Hope you have enjoyed this article. In the next blog post, we will discuss Get-ItemProperty cmdlet in PowerShell.
To Set more details on PowerShell, kindly follow below official documentation