PowerShell Set-ItemProperty Cmdlet
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed Get-ItemProperty cmdlet in PowerShell.
https://cloudaffaire.com/powershell-get-itemproperty-cmdlet/
In this blog post, we will discuss Set-ItemProperty cmdlet in PowerShell. You can use Set-ItemProperty cmdlet to set a property of an item in a specific location defined in the path parameter. Set-ItemProperty cmdlet is mainly used to modify properties of the file, directory, and registry key. For example, you can use Set-ItemProperty cmdlet to make a file read-only.
Set-ItemProperty Cmdlet Syntax:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
## Set-ItemProperty ## [-Path] ## [-Name] ## [-Value] ## [-PassThru] ## [-Force] ## [-Filter ## [-Include ## [-Exclude ## [-Credential ## [-WhatIf] ## [-Confirm] ## [-UseTransaction] ## [ |
Set-ItemProperty Cmdlet Argument List:
- –Confirm: Prompts you for confirmation before running the cmdlet.
- –Credential: To impersonate another user or elevate your credentials.
- –Exclude: Specifies those items upon which the cmdlet does not act, and includes all others. The value of this parameter qualifies the Path parameter.
- –Filter: Specifies a filter in the format or language of the provider. The value of this parameter qualifies the Path parameter.
- –Force: Forces the cmdlet to set a property on items that cannot otherwise be accessed by the user.
- –Include: Specifies only those items upon which the cmdlet acts, which excludes all others. The value of this parameter qualifies the Path parameter.
- –InputObject: Specifies the object that has the properties that this cmdlet changes. Enter a variable that contains the object or a command that gets the object.
- –LiteralPath: Specifies a path of the item property. Unlike the Path parameter, the value of LiteralPath is used exactly as it is typed.
- –Name: Specifies the name of the property.
- –PassThru: Returns an object that represents the item property. By default, this cmdlet does not generate any output.
- –Path: Specifies the path of the items with the property to modify.
- –Type: Type is a dynamic parameter that the Registry provider adds to the Set-ItemProperty cmdlet. This parameter only works in the registry drives. The acceptable values for this parameter are:
- String: Specifies a null-terminated string. Equivalent to REG_SZ.
- ExpandString: Specifies a null-terminated string that contains unexpanded references to environment variables that are expanded when the value is retrieved. Equivalent to REG_EXPAND_SZ.
- Binary: Specifies binary data in any form. Equivalent to REG_BINARY.
- DWord: Specifies a 32-bit binary number. Equivalent to REG_DWORD.
- MultiString: Specifies an array of null-terminated strings terminated by two null characters. Equivalent to REG_MULTI_SZ.
- Qword: Specifies a 64-bit binary number. Equivalent to REG_QWORD.
- Unknown: Indicates an unsupported registry data type, such as REG_RESOURCE_LIST.
- –UseTransaction: Includes the command in the active transaction. This parameter is valid only when a transaction is in progress.
- –Value: Specifies the value of the property.
- –WhatIf: Shows what would happen if the cmdlet runs. The cmdlet is not run.
PowerShell Set-ItemProperty Cmdlet:
Change Properties Of A Directory In PowerShell:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
############################################ ## PowerShell | Cmdlet | Set-ItemProperty ## ############################################ ## PowerShell Latest Version (5) ## create a file, directory and registry key New-Item -Path HKCU:\Software -Name MyRegKey New-Item -Path HKCU:\Software\MyRegKey -Name Cloud -Value "Affaire" New-Item -ItemType Directory -Path C:\MyDir\ New-Item -ItemType Directory -Path C:\MyDir\MyDir1 New-Item -ItemType File -Path C:\MyDir\MyFile1 ## change properties of a directory in PowerShell Get-ItemProperty -Path C:\MyDir\MyDir1 -Name CreationTime Set-ItemProperty -Path C:\MyDir\MyDir1 -Name CreationTime -Value (Get-Date) Get-ItemProperty -Path C:\MyDir\MyDir1 -Name CreationTime |
Change Properties Of A File In PowerShell:
1 2 3 4 5 |
## change properties of a file in PowerShell Get-ItemProperty -Path C:\MyDir\MyFile1 -Name IsReadOnly Set-ItemProperty -Path C:\MyDir\MyFile1 -Name IsReadOnly -Value $true Get-ItemProperty -Path C:\MyDir\MyFile1 -Name IsReadOnly |
Change Properties Of A Registry Key In PowerShell:
1 2 3 4 5 6 7 8 9 10 |
## change properties of a registry key in PowerShell Get-ItemProperty -Path HKCU:\Software\MyRegKey\Cloud Set-ItemProperty -Path HKCU:\Software\MyRegKey -Name Cloud -Value "AWS" Get-ItemProperty -Path HKCU:\Software\MyRegKey\Cloud ## remove the items created for this demo Remove-Item -Path HKCU:\Software\MyRegKey -Recurse Remove-Item -Path C:\MyDir -Recurse -Force |
Hope you have enjoyed this article. In the next blog post, we will discuss Get-ChildItem cmdlet in PowerShell.
To Set more details on PowerShell, kindly follow below official documentation