((gwmi win32_volume)[0]).Defraganalysis()
[0] are the index of the drive currently bein defragged. Usually index 0 is the C drive, 1 is the D drive and so on. To check this, run gwmi win32_volume
To see what the ReturnValue means:
http://msdn.microsoft.com/en-us/library/aa389832(VS.85).aspx
I`ll let you know if I can dig up some more information.
Ya, I have all that in the script now, including a switch for returnvalue (successful, dirty bit, not enough free space, etc). What I want to do is come behind that after 'x' period of time, do an analysis and if -ne successful (returnvalue of 0), stop the defrag. It's the stop part I can't seem to find info on, or perhaps it's because it doesn't exist. I've looked at the callcancel feature, but not sure how that works. Not sure if it would actually stop the defrag (gracefully, which is what I would want), of if it simply tells powershell to go on without waiting on return/response from last call/command.
$a = new-object -com WbemScripting.SWbemSink
http://msdn.microsoft.com/en-us/library/aa393877(VS.85).aspx
Hey TobieJ,
Were you successful getting your defrag script processing to end cleanly if it ran overtime? I have a similar requirement - have to shutdown defrags when prime shift starts - but have been totally unsuccesful getting any automated stop to work.
Are you willing / able to share you script(s)?
thanks, Roland