title: Powershell: Why does write-output and write-warning treat strings and variables differently?
body: <p>I'm relatively new to powershell, and I have found an oddity that I'm not sure how to explain.</p>
  
  <p><strong>This outputs just fine.</strong></p>
  
  <pre><code>write-output $var.Name.padright(40)" - "(get-date -format s)" : Creating on $var1"
  </code></pre>
  
  <p><strong>This on the other hand, throws an error:</strong></p>
  
  <pre><code>write-warning $var.Name.padright(40)" - "(get-date -format s)" : Creating on $var1"
  
  Write-Warning : A positional parameter cannot be found that accepts argument ' - '.
  At Y:\test.ps1:228 char:22
  +         write-warning &lt;&lt;&lt;&lt;  $var.name.padright(40)" - "(get-date -format s)" : Creating on $var1"
  + CategoryInfo          : InvalidArgument: (:) [Write-Warning], ParameterBindingException
  + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.WriteWarningCommand
  </code></pre>
  
  <p><strong>Any idea why? If I want to make the above work, I instead do this:</strong></p>
  
  <pre><code>$warning = $var.Name.padright(40) + " - " + (get-date -format s) + " : Creating on $var1"
  write-warning $warning
  </code></pre>
  
  <p>I've found a workaround, as you can see, but I'd like to understand why string concatenation works differently for write-output than write-warning. Is there a reason I should explicitly create the string as a variable first rather than just using the shorthand?</p>