title: Powershell String Length Validation
body: <p>I created a really simple <code>HelloWorld.ps1</code> Power-shell script which accepts a <code>Name</code> parameter, validates its length and then prints a hello message, for example if you pass <code>John</code> as <code>Name</code>, it's supposed to print <code>Hello John!</code>.</p>
  
  <p>Here is the Power-shell script:</p>
  
  <pre><code>param (
      [parameter(Mandatory=$true)]
      [string]
      $Name
  )
  # Length Validation
  if ($Name.Length &gt; 10) {
      Write-Host "Parameter should have at most 10 characters."
      Break
  }
  Write-Host "Hello $Name!"
  </code></pre>
  
  <p>And here is the command to execute it:</p>
  
  <pre><code>.\HelloWorld.ps1 -Name "John"
  </code></pre>
  
  <p>The strange behavior is every time that I execute it:</p>
  
  <ul>
  <li>It doesn't perform validation, so it accepts <code>Name</code> parameters longer than 10 characters.</li>
  <li>Every time I execute it, it creates and updates a file named <code>10</code> without any extension.</li>
  </ul>
  
  <p>What's the problem with my script and How can I validate string length in PowerShell?</p>