title: Powershell issues with parameters: 'Cannot convert value "" to type "System.Boolean"'
body: <p>I wrote a PowerShell utility that takes in a couple parameters, and transfers files from a source directory to a destination directory.</p>
  <p>Initially, all was done as a single function, and worked well enough.</p>
  <p>Before adding some features, I broke repeated logic into its own function.</p>
  <p>Then, the <strong>ISSUES</strong> began.</p>
  <p>It appears that the <code>Param()</code> variables are seeded with incorrect values. Running the script yields the following:</p>
  <pre><code>PS ...&gt; .\photoTransfer.ps1 E:\DCIM\100OLYMP
  
  Cannot convert value &quot;&quot; to type &quot;System.Boolean&quot;. Boolean parameters accept only Boolean values and numbers, such as
  $True, $False, 1 or 0.
  At C:\Users\SWPhantom\Desktop\admin\photoTransfer.ps1:85 char:3
  +   [Parameter(Mandatory=$true, Position = 0, HelpMessage = &quot;The path o ...
  +   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : MetadataError: (:) [], ArgumentTransformationMetadataException
      + FullyQualifiedErrorId : RuntimeException
  </code></pre>
  <p>I can confirm that something's strange with
  <code>Write-Output &quot;src: $source&quot;</code>, which spits out <code>src: True</code>. (Expected to be <code>src: E:\DCIM\100OLYMP</code>)</p>
  <p><strong>HOWEVER</strong>: I can get the value I expect to be passed in with an <code>$args[0]</code>.</p>
  <p>I expect that the issue is simple, but I can't pick up on it, as this was my first foray into more... mature PowerShell scripting.</p>
  <p>I am getting around the immediate problem by using the <code>$args[i]</code> method, but it'd be nice to not get an error message and use the seemingly Nice and orderly Params. (Especially since they seemed to work before I made the separate <code>Transfer</code> function).</p>
  <p>Thanks!</p>
  <p>Full code:</p>
  <pre><code># Purpose: Transfer all photos from a memory card, to a destination folder, organized by year, month, date.
  # Ensure that the Date Modified and Date Created is preserved.
  
  function Transfer {
    Param(
      [Parameter(Mandatory, Position = 0)]
      [string]$src,
  
      [Parameter(Mandatory, Position = 1)]
      [string]$dst,    
  
      [Parameter(Mandatory, Position = 2)]
      [string]$extension
    )
  
    # Look at the source directory. Enumerate files to be sent over. (Only copy .ORF/.MOV files)
    $files = Get-ChildItem -Path $src -Include $extension -Recurse
    $numberOfFiles = $files.Count
  
    if($numberOfFiles -eq 0) {
      return &quot;No $extension files found in $src!&quot;
    }
  
    # Give user last chance to stop program. Show them number of files and destination folder.
    Write-Output &quot;Ensure the action is correct:&quot;
    read-host &quot;Copying $numberOfFiles files from $src to $dst ?`nPress Enter to continue&quot;
  
    # Iteration for progress tracking.
    $iter = 1
    # Foreach file, check the Date Modified field. Make sure the destination folder has the folder structure like:
    # Drive/Photos/YYYY/MM/DD/
    # Where the YMD matches the Date Modified field of every photo.
    foreach ($file in $files) {
      $originalCreationTime = $file.LastWriteTime
  
      [string]$year = $file.LastWriteTime.Year
      [string]$month = $file.LastWriteTime.Month
      [string]$date = $file.LastWriteTime.Day
      
      # Add leading zero, if necessary
      if($month.length -lt 2) {
        $month = &quot;0&quot; + $month
      }
      if($date.length -lt 2) {
        $date = &quot;0&quot; + $date
      }
  
      # Test the path of destinationPath/YYYY/MM/DD/
      $path = $dst + &quot;$year\$month\$date\&quot;
      if (!(Test-Path -Path $path)) {
        if($verb) {
          Write-Output &quot; $path&quot;
        }
  
        New-Item -ItemType Directory -Path $path
      }
  
      # The filepath exists!
      if($verb) {
        Write-Output &quot;  ($iter/$numberOfFiles) $file -&gt; $path&quot;
      }
      $iter += 1
  
      Copy-Item $file.FullName -Destination $path
  
      # Fix the Creation Time
      $(Get-Item -Path &quot;$path$($file.Name)&quot;).CreationTime=$originalCreationTime
    }
  
    Write-Output &quot;`nCopying done!`n&quot;
  
    # Delete items?
    Write-Output &quot;Delete $numberOfItems items?&quot;
    $del = read-host &quot;Deleting copied files from $src ?`nY to continue&quot;
  
    if($del -eq &quot;Y&quot;) {
      foreach ($file in $files) {
        Remove-Item $file.FullName
      }
    }
  }
  
  Param(
    # Source Folder
    [Parameter(Mandatory=$true, Position = 0, HelpMessage = &quot;The path of the source of the media&quot;)]
    [Alias(&quot;s&quot;)]
    [string]$source,
  
    # Photo Destination
    [Parameter(Mandatory=$false, Position = 1, HelpMessage = &quot;The path of the folder you want to move photos to&quot;)]
    [Alias(&quot;pd&quot;)]
    [string]$photoDestination,
  
    # Video Destination
    [Parameter(Mandatory=$false, Position = 2, HelpMessage = &quot;The path of the folder you want to move videos to&quot;)]
    [Alias(&quot;vd&quot;)]
    [string]$videoDestionation,
  
    # Verbosity
    [Parameter(Position = 3, HelpMessage = &quot;Turn extra logging on or off&quot;)]
    [Alias(&quot;v&quot;)]
    [bool]$verb = $true
  )
  
  $usageHelpText = &quot;usage:`n photoTransfer.ps1 &lt;DriveName&gt; &lt;pathToDestinationRootFolder&gt;`nex:`n .\photoTransfer.ps1 C T:\Photos&quot;
  
  
  #TODO: Solve this conundrum, where passing a via CMD
  # Write-Output &quot;Source before treatment: $($args[0])&quot;
  # Write-Output &quot;Source before treatment: $($args[1])&quot;
  # Write-Output &quot;Source before treatment: $($args[2])&quot;
  # Write-Output &quot;Source before treatment: $($args[3])&quot;
  $source = $args[0]
  $verb = $true
  
  
  
  # I expect a drive name. If a ':' is missing, I add it.
  if(!$source.Contains(&quot;:&quot;)) {
    $source = $source + &quot;:&quot;
  }
  
  # The assumption is that the photos are coming from my Olympus camera, which has the following path to the files.
  # $olympusFolderPath = &quot;DCIM\100OLYMP\&quot;
  # $source += $olympusFolderPath
  
  # Make sure the destination path has a terminating '\'
  # if(!($photoDestination -match &quot;\\$&quot;)) {
  #   $photoDestination = $photoDestination + &quot;\&quot;
  # }
  
  $photoDestination = &quot;T:\Photos\&quot;
  $videoDestionation = &quot;T:\Footage\&quot;
  
  
  # Check if the source and destination paths are valid.
  if (!(Test-Path -Path $source)) {
    Write-Output &quot;Source disk ($source) doesn't exist`n$usageHelpText&quot;
    exit 0
  }
  
  if (!(Test-Path -Path $photoDestination)) {
    Write-Output &quot;Destination path ($photoDestination) doesn't exist`n$usageHelpText&quot;
    exit 0
  }
  
  if (!(Test-Path -Path $videoDestionation)) {
    Write-Output &quot;Destination path ($videoDestionation) doesn't exist`n$usageHelpText&quot;
    exit 0
  }
  
  Transfer $source $photoDestination &quot;*.ORF&quot;
  Transfer $source $videoDestionation &quot;*.MOV&quot;
  </code></pre>