title: How can i find file sizes with powershell
body: <p>We're migrating servers and sometimes the copy of various files doesn't happen successfully and, for example, we end up with PDF files that are 1kb rather than their actual size.</p>
  
  <p>I wrote a simple powershell script to find these files, but it also listed the empty subfolders at the end of the search results.  So i'd see something like this in my output text file -
  C:\path\filename1.pdf
  c:\path\filename2.pdf
  c:\path\subfolder\</p>
  
  <p>What' i'm trying to do is eliminate the empty folders in the results.  I've modified the original script -</p>
  
  <pre><code>Clear
  $username = $env:username
  Get-ChildItem -path "C:\users\blah\blah\blah\" -recurse | Where 
  {$_.Length -lt 1025 } | Sort-Object length | ft fullname, length -AutoSize 
  |Out-File "C:\Users\$username\Desktop\1kb_Files.txt"
  </code></pre>
  
  <p>In the modified script i've created a read-host to grab the file size to search, but then when i add that variable into the script i get an error.  Here's hte modified script -</p>
  
  <pre><code>$Size = Read-Host "Enter search size"
  $folder = Read-Host "Enter full search path"
  Get-ChildItem -path $folder -recurse |Where {($_.Length -lt '$size') -and ($_.Length -gt '0')}
  </code></pre>
  
  <p>But now i get this error - 
  Cannot convert value "$size" to type "System.Int64". Error: "Input string was not in a correct format."</p>
  
  <p>I'm guessing i need to define the size for $size?</p>