Setting the mode and extended file and folder attributes
When you want to change the mode and the extended attributes of a file or folder, you need to access the extended property named Attributes
. The Attributes
property allows you to read and write to itself. This means that if you want to replace all of the file or folder attributes, you can just declare the new Attributes
and set them to the Attributes
property. Likewise, if you want to maintain the existing Attributes
but want to add new Attributes
, you declare a variable and call the existing Attributes
property; then you add the new Attributes
using a comma separator. You then set that new variable to the Attributes
property of a file or folder.
To view and add a new extended file attribute, do the following action:
# Get file attributes $file = get-item –path "c:\Program Files\MyCustomSoftware\Graphics\FirstGraphic.png" $attributes = $file.attributes $attributes # Append ReadOnly attribute to existing attributes $newattributes = ...