title: Substring in a PowerShell function
body: <p>I've got a function which works fine.
  It pulls the first character of the firstname and the whole lastname from a text box in a PowerShell GUI and then it creates a sAMAccountName from both.
  Now I need only the first 8 characters from the generated sAMAccountName.</p>
  
  <p>Here is the function</p>
  
  <pre><code>Function Set-sAMAccountName {
      Param([Switch]$Csv=$false)
      if(!$Csv)
          {
          $GivenName = $txtFirstName.text
          $Surname = $txtLastName.text
          }
      else{}
      Switch($XML.Options.Settings.sAMAccountName.Style | Where{$_.Enabled -eq $True} | Select -ExpandProperty Format)
          {
          "FirstName.LastName"    {"{0}.{1}" -f $GivenName,$Surname}
          "FirstInitialLastName"  {"{0}{1}" -f ($GivenName)[0],$Surname}
          "LastNameFirstInitial"  {"{0}{1}" -f $Surname,($GivenName)[0]}
          Default                 {"{0}.{1}" -f ($GivenName)[0],$Surname}
          }
      }
  </code></pre>
  
  <p>Any ideas?
  Thx a lot in advance</p>