header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Win32_Directory CompressEx
Last Post 28 Jun 2010 01:38 PM by Shinedog. 2 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
ShinedogUser is Offline
New Member
New Member
Posts:6
Avatar

--
28 Jun 2010 12:05 PM
    I am trying to use the CompressEx method of the Win32_Directory class to compress the %systemroot%\system32\LogFiles directory during a server build process. The code I am currently using is

    (Get-WmiObject -class "Win32_Directory" -filter "name='$systemroot\\System32\\LogFiles'" -ErrorVariable errorstatus -ErrorAction SilentlyContinue).CompressEx("",$true)

    This works great for compressing a folder and its subfolders and files. However, the problem with this method is that when it hits an error, a sharing violation in my case, it stops the process and stores the file on which it errored in .StopFileName. The method does not appear to have any kind of "SilentlyContinue" type functionality to it. From what I gathered on this method, you should be able to take the .StopFileName value and plug it back in as the StartFileName (shown as "" in my example above) and run it again. But this doesn't work either as it just fails on the same file again. Seems like you really need .StopFileName + 1 in the array of folders/files it builds but of course you can't touch that array.

    I suppose as a workaround, I can build by own array of subfolders under \LogFiles and step through using the .Compress method instead which would just compress the folder and thus any new files created under those folders which is my intent really. But I'd like to know how to error handle .CompressEx. Anyone familiar with this method?

    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1643
    Avatar

    --
    28 Jun 2010 12:09 PM
    That's a really interesting problem. I might actually approach this be possibly querying WMI and/or .NET experts on this. I do believe you are going to be out of luck on this one. Even if PowerShell can be set to handle the error, it will not continue to move on to the next file, it will want to basically move to the next command... Regardless of it being one of the 2 major types of errors: terminating or non-terminating.
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    ShinedogUser is Offline
    New Member
    New Member
    Posts:6
    Avatar

    --
    28 Jun 2010 01:38 PM
    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.

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer