I tried that to add an attribute to a file/folder
Get-ChildItem '$PATH' -Recurse | foreach{$_.Attributes = $_.Attributes + 'Compressed'}
Problem is that it create a cycle like that : Not compressed
> Compressed
> Compressed, Offline
> Compressed, NotContentIndexed
> Compressed, Offline, NotContentIndexed
So the command should work fine on any element on $PATH that aren't compressed at all, but if there is the attribute, it will add/delete Offline, NotContentIndexed
to the attributes (Compressed
and any other irrelevant attributes stays fine), considering that I never asked for that. I only want to add/let Compressed
without touching anything else
Compressed
without touching anything else"Attributes
is a bitmap, and you don’t want to do ordinary arithmetic on a bitmap; you need a logical operation. Can you do$_.Attributes = $_.Attributes | 'Compressed'
?(Get-Item -Path 'X:\theFileOrFolder').Attributes -band 'Compressed'
If that returns 'Compressed', then... it is compressed otherwise it is not. Is that what you mean? (-band
stands for Binary AND and in this case it test for the bitmap including the value 2048 or not. 'Compressed' is easier to write than the numeric value and PowerShell will understand that)