Setting the Archive bit in a file tree

I have built an advanced function (with previous help from members - Thanks!) that will clear the archive bit in a collection of files. Here is the code:

function Clear-ArchiveBit
        # Param1 help description



    {$Var3=Get-ChildItem -Path $Path -Recurse
      foreach($file in $var3){
        if((Get-ItemProperty -Path $file.FullName).Attributes -band $attribute)
         Set-ItemProperty -Path $file.fullname -Name attributes -value ((Get-ItemProperty $file.fullname).attributes -BXOR $attribute) -Force}      

This code worked fine on one set of files under a parent folder which I had named “My_Archive”, but strangely enough it failed when run against a second set of files under a parent “My_Archive_2”
The error message produced was:
Set-ItemProperty : The attribute cannot be set because attributes are not supported. Only the following attributes can be set: Archive, Hidden, Normal, ReadOnly, or System.
At C:\Users\Peter\Documents\Powershell_Scripts\ClearArchiveBits.ps1:35 char:10

  •      Set-ItemProperty -Path $file.fullname -Name attributes -valu ...
  •      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : ReadError: (FileAttributes attributes=Directory:PSNoteProperty) [Set-ItemProperty], IOException
    • FullyQualifiedErrorId : SetPropertyError,Microsoft.PowerShell.Commands.SetItemPropertyCommand
      I finally determined that this appears to be a Windows problem, not a powershell problem. The only difference between these two sets of files that I can find is a check box found when you right click on a file, select “properties” then under the “General” tab, select “advanced”. In the “My_Archive_2” head folder, and all sub folders and files, the selection “Allow this file to have contents indexed in addition to file properties” is unchecked. I can’t determine if this represents a file attribute, or a permission, or even why it was different in the first place, except that I probably managed to change it months ago when messing around with file attributes. (Before learning Powershell.) I also have a query posted in a Windows 7 forum about this. Could Powershell be used to change this file feature?

That isn’t actually an attribute of the file; it’s passed to Windows’ indexing service. I’ve never seen anyplace where that’s instrumented for PowerShell.

Don, the “allow this file…” check box may not be a true attribute, but it’s value is in the file attribute byte(s) at the 2^13 or 8192 position. I was able to use powershell to determine the decimal value of the file attributes: when the box is unchecked, this bit is set, and the decimal value will be 8192 plus whatever other bits are set (eg. plus readonly gives 8193). Although Powershell allows one to see attributes, it is limited in what can be changed using Boolean expressions. I finally gave up on trying to fix this indexing option in my archive file tree, and took a different approach. It turned out that when I created a new archive folder under “MyDocuments” and then copied all sub-folders and files to this new location, the files now had the “allow this file…” box checked, and my Powershell cmdlets worked! Problem solved.

The module I created for archiving has the following cmdlets: Get-ArchiveSize; Clear-ArchiveBit; Set-ArchiveBit; Get-FilesReadyToArchive; Copy-FilesReadyToArchive; Remove-PaperpotFiles (These are created by the scanning software and are hidden); Save-TableOfContents (in a .html file); and finally Write-TableOfContents.

By being able to manipulate the Archive bit in Windows, I can keep adding new files to the categories created in my archive folder (for example, continuing tax returns or Visa statements), and then copy just those new files to storage; then the archive bit for those new files can be cleared. Do you think anyone would be interested in this module?