Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CompressEx on a folder w/ Recursive syntax??

Status
Not open for further replies.

shinedog

MIS
Feb 24, 2004
60
0
0
US
Having some trouble with the syntax for compressing a folder and all its subfolders/files. The Win32_Directory WMI class has the method CompressEx which has a recursive parameter which is supposed to then compress all subfolders/files under the initial folder.

If I call

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

It compresses the folder %systemroot%\system32\LogFiles properly but of course without passing the Recursive parameter, it doesn't hit any of the subfolders/files. I'm not sure if this is just because it is Monday morning, but I can't for the life of me figure out how to pass the recursive boolean to this method. The method shows

uint32 CompressEx(
[out] string StopFileName,
[in, optional] string StartFileName,
[in, optional] boolean Recursive
);

I don't really care about the [out] but I'm thinking I'm getting caught up on the first optional [in] which I don't need as I'm already specifying the folder patch in the Get.

Anyone know the proper syntax for passing the recursive parameter?
 
Well apparently I shouldn't script first thing Monday morning as I was passing the first [in] as null which it didn't like.

Bad code:

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

Good code:

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

However, since it's the LogFiles directory, some of these files are in use and it stops dead with a sharing violation return code instead of continuing on which I now have to see if I can work around.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top