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 { [CmdletBinding()] [OutputType([int])] Param ( # Param1 help description [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=0)] $Path, $attribute=[io.fileattributes]::archive ) Begin { } Process {$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?
Peter