Yeah, it's obviously more of a WMI thing, kind of seems like a flaw in the .Compress and .CompressEx methods. I just worked around the issue using the following code instead
$systemroot = $env:systemroot
$path = "$systemroot\system32\LogFiles" -replace '\\','\\'
(Get-WmiObject -class "Win32_Directory" -filter "name='$path'" -ErrorVariable errorstatus -ErrorAction SilentlyContinue).Compress()
foreach($folder in Get-ChildItem $path | where {$_.psIsContainer -eq $true}) {
$a = $folder.fullname -replace '\\','\\'
(Get-WmiObject -class "Win32_Directory" -filter "name='$a'" -ErrorVariable errorstatus -ErrorAction SilentlyContinue).Compress()
}
It still hits the sharing violation when it compresses the subfolder that contains the in-use file(s) as .Compress also attempts to compress any files under the subfolder. But since the folder is marked as compressed first, it achieves my desired result in that any new logs created when rolling over are created as compressed. A real kludge and not desirable if I was doing this on existing servers where \LogFiles might already contain existing files but fits my immediate needs.