Repair-clustersharedvolume

Welcome Forums General PowerShell Q&A Repair-clustersharedvolume

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
2 years, 10 months ago.

  • Author
    Posts
  • #32969

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    Thanks!

The topic ‘Repair-clustersharedvolume’ is closed to new replies.