title: How to compare a folder size in Powershell
body: <p>I have to apply a command IF the folder size is greater or equal to 600MB.</p>
  
  <p>I tried something like this </p>
  
  <pre><code>$folders = Get-ChildItem d:\home -exclude *.*
  function Get-Size
  {
   param([string]$pth)
   "{0:n2}" -f ((gci -path $pth -recurse | measure-object -property length -sum).sum /1mb)
  }
  
  
  ForEach ($subFolder in $folders){
  
  echo $subFolder | select-object fullname
  $size = Get-Size $subFolder
  echo $size
  
      if ($size -gt "600") { echo "Not ok." }
      else { echo "OK template." }
  
  }
  </code></pre>
  
  <p>It doesn't work. It writes the right size of the folder but the IF statement is not respected. How do I do?</p>