Powershell

How to Use the Set-ItemProperty (Microsoft.PowerShell.Management)?

In PowerShell, the “Set-ItemProperty” cmdlet is used to set or alter the property value of a mentioned item. Moreover, it can change or establish the properties of an item. For instance, it can alter the value of an “IsReadOnly” property file object to “$True”. It can also assist to alter/change the registry values.

In this tutorial, we will briefly explain about the “Set-ItemProperty” cmdlet.

How to Use the Set-ItemProperty (Microsoft.PowerShell.Management)?

The “Set-ItemProperty” cmdlet is used to set or alter the property value of a specified item or file. Let’s explore some of the examples to know more about the stated cmdlet.

Example 1: Use the “Set-ItemProperty” Cmdlet to Modify an Item

Execute the below-mentioned code to modify a single item:

Get-ChildItem C:\Docs\New.txt | Set-ItemProperty -Name IsReadOnly -Value $True

 
In the above-given code:

    • First, specify the “Get-ChildItem” cmdlet and add the path of an item alongside the “|” pipeline.
    • After that, write the “Set-ItemProperty” with the “-Name” parameter having the “IsReadOnly” value assigned to it.
    • Lastly, use the “-Value” parameter and assign it the “$True” value:

 

Example 2: Utilize the Cmdlet “Set-ItemProperty” to Set a Property of a File

Run the below-given command to set a file’s property in PowerShell:

Set-ItemProperty -Path C:\Docs\New.txt -Name IsReadOnly -Value $true

 
According to the above code:

    • Initially, write the “Set-ItemProperty” cmdlet.
    • Then, add the parameter “-Path” and set the file path.
    • Lastly, mention the “-Name” and the “-Value” parameter having the stated value assigned:

 

Example 3: Use the “Set-ItemProperty” Cmdlet to Modify a Registry Key Value

To modify a registry key in PowerShell, execute the following command:

Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -Name "AutoAdminLogon" -Value "1"

 
Here, first, specify the “Set-ItemProperty” cmdlet along with the stated registry value. After that, write the “-Name” and “-Value” parameters having the stated values assigned:


That was all about the “Set-ItemProperty” cmdlet in PowerShell.

Conclusion

The cmdlet “Set-ItemProperty” in PowerShell is responsible for altering or creating the value of a property of an item. It can change the values of text files and also registry values. This post has elaborated on the PowerShell “Set-ItemProperty” cmdlet in detail.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.