I have a Powershell script that copies files from one location to another. Once the copy is complete I want to clear the Archive attribute on the files in the source location that have been copied.
How do I clear the Archive attribute of a file using Powershell?
To view or change the attributes of a file, right-click the file, and then click Properties. In the "Attributes:" section, enabled attributes have checks beside them. Add or remove the checks from Read-only, Archive, or Hidden to enable or disable these options.
To access those settings, click the PowerShell icon in the top-left corner of the console window and click Properties to open the Properties dialog box. The Properties dialog box includes four tabs—Options, Font, Layout, and Colors—each of which contain configuration settings that you can modify as necessary.
The MS-DOS "Attrib" command allows you to add and remove attributes from a file -- even if the file is hidden or you cannot start Windows. You can also use this command to modify the attributes of a system file, archive file or read-only file -- or to see the attributes of a file without modifying anything.
You can use the good old dos attrib command like this:
attrib -a *.*
Or to do it using Powershell you can do something like this:
$a = get-item myfile.txt $a.attributes = 'Normal'
As the Attributes is basically a bitmask field, you need to be sure clear the archive field while leaving the rest alone:
PS C:\> $f = get-item C:\Archives.pst PS C:\> $f.Attributes Archive, NotContentIndexed PS C:\> $f.Attributes = $f.Attributes -band (-bnot [System.IO.FileAttributes]::Archive) PS C:\> $f.Attributes NotContentIndexed PS H:\>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With