title: Switch Parameter and an If Statement
body: <p>I am trying to use the value of a switch parameter as the trigger to write to a csv file if the parameter is called with the script from the command line.  However, with my current code the csv file is created whether I include the parameter or not.  What's up with that?</p>
  
  <p>Also, is there a better way to handle my else/if else/if else section?</p>
  
  <pre><code>[CmdletBinding()]
  param (
      [Parameter(Mandatory=$true)]
      [string]$dir,
      [Parameter(Mandatory=$true)]
      [int]$days,
      [switch]$csv=$false
  )
  
  Process {
      Clear-Host
      $totSize = 0
      $totFiles = 0
      $modDate = (Get-date).AddDays(-$days).Date
      $modfiles = Get-ChildItem -Path $dir -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.LastWriteTime -ge $modDate } 
      If ($csv = $true){
          $modfiles | Select-Object -Property FullName, Length,LastWriteTime | Export-Csv -Path .\modFiles.csv -NoTypeInformation
      }
      foreach ($file in $modfiles){
          $totFiles = $totFiles + 1
          $totSize = $totSize + $file.Length 
      }
  
      If ($totSize -lt 1MB){
          $outSize = $totSize/1KB
          $unit = "KB"
      }
      elseif (($totSize -ge 1MB) -and ($totSize -lt 1GB)){
          $outSize = $totSize/1MB
          $unit = "MB"   
      }
      elseif ($totSize -ge 1GB){
          $outSize = $totSize/1GB
          $unit = "GB" 
      } 
  
      $outRound = [math]::Round($outSize,2)
      Write-Host $totFiles "Files"
      Write-Host $outRound $unit
  }
  </code></pre>