This topic contains 2 replies, has 2 voices, and was last updated by  37mm 2 years, 7 months ago.

  • Author
  • #32969


    Repair-ClusterSharedVolume "bigCSV" -Defrag -Parameters /a

    I am trying to get the Value of the total fragmented space. I would like to to automate a check, to initiate a defrag at +10% fragmentation. I am stuck on trying to pull the total fragmented space value and assign it to variable. Thanks in advance!

  • #32978

    Matt Bloomfield

    I don't have anything using CSV to test this with but reading the docs it seems to just pass the command off to defrag.exe, is that correct? If so, do you just get back the output from defrag.exe? Something like this should work:

    [int]$fragmentation = (((defrag f: /A | Select-String 'Total fragmented space') -split '=') -replace '%','').trim()[1]

    Select-String gets the relevant line from the output. We split that on the equals sign which gives us a collection containing two strings 'Total fragmented space' and 'n%'. We remove the % sign by replacing it with nothing and then trim the leading space. We then choose the second string from the collection (which has the index 1).

  • #33051



You must be logged in to reply to this topic.