Question

I have this command that runs fine on more than 100 servers (2008R2, powershell 2), except for one particular server where it kills it's memory ( powershell.exe consume more than 6 GB RAM).

Get-ChildItem -Path E:\ -Exclude Thumbs.db,"$RECYCLE.BIN*","~$*","System Volume Information" -recurse -force  | where {$_.Attributes -NotMatch "Archive"} | %{$_.Attributes = [System.IO.FileAttributes]::Archive}

Can somebody explains this ? Is there a more efficient way of setting archive attribute on volumes of around 200GB size ?


update it seems that it's the exclude parameter the culprit : i can see the the $recycle.bin dir in the processed files.

Was it helpful?

Solution

the problem is that -exclude parameter will fail if get-childitem is launched on the root of drives (same problem on PS V3). More details here : http://powershell.com/cs/forums/p/12202/21382.aspx#21382

here is my poor workaround :

$exclude=@('$RECYCLE.BIN',"SYSTEM VOLUME INFORMATION","Thumbs.db")
ls e: | ?{ $exclude -notcontains $_.name  }|%{
    ls -recurse -force $_.fullname} |%{ 
    $_.attributes=[System.IO.FileAttributes]::Archive
}

Unfortunatly i cannot use wildcars with this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top