Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Clear all file attributes

$
0
0

So i'm trying to clear all file attributes and just set Archive bit,

Currently I have Archive,Offline.  I recalled a file from an object store and it still says its offline

 

gci file | Select attributes

 

Archive,Offline

 

I wanted to force clear all the attributes but I couldn't figure out the best way to do this.

 

I found a few links on google, including the this code

 

 

functionGet-FileAttribute{
param($file,$attribute)
$val= [System.IO.FileAttributes]$attribute;
if((gci $file-force).Attributes-band$val-eq$val){$true;} else { $false; }
}



functionSet-FileAttribute{
param($file,$attribute)
$file=(gci $file-force);
$file.Attributes=$file.Attributes-bor ([System.IO.FileAttributes]$attribute).value__;
if($?){$true;} else {$false;}
}



functionClear-FileAttribute{
param($file,$attribute)
$file=(gci $file-force);
$file.Attributes-= ([System.IO.FileAttributes]$attribute).value__;
if($?){$true;} else {$false;}
}

Viewing all articles
Browse latest Browse all 6937

Trending Articles