title: How do I properly handle spaces in file names passed as arguments to a PowerShell script via a SendTo shortcut?
body: <p>I've written a (very) simple script that appends the current date to a given file name in PowerShell, and I've set it up with a SendTo shortcut for easy access.</p>
  
  <p>However, it doesn't handle file names with spaces in them very well. If a file name is <strong>"thisFile.txt"</strong> it correctly adds the date, making it <strong>"thisFile.txt.20121227"</strong>, but if the file name is <strong>"this File.txt"</strong> it doesn't work from the SendTo shortcut I've set up.</p>
  
  <p>It does work from the command line for both types of file names, however, and I've been scratching my head trying to figure out why.</p>
  
  <p>This is the snippet of code I've been using:</p>
  
  <pre><code>$enddate = (Get-Date).toString("yyyyMMdd")
  $filename = $arg
  
  foreach ($filename in $args) {
      Rename-Item $filename $filename"."$enddate
  }
  </code></pre>
  
  <p>This is in the Target field for the shortcut I've set up:</p>
  
  <pre><code>"%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe " -NonInteractive  -WindowStyle Hidden -NoProfile -noexit &amp;"C:\Scripts\adddate.ps1"
  </code></pre>