Repair-clustersharedvolume

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of 37mm 37mm 1 year, 1 month ago.

  • Author
    Posts
  • #32969
    Profile photo of 37mm
    37mm
    Participant

    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
    Profile photo of Matt Bloomfield
    Matt Bloomfield
    Participant

    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
    Profile photo of 37mm
    37mm
    Participant

    Thanks!

You must be logged in to reply to this topic.