title: Powershell Get number from string
body: <p>Hi all I am trying to get the number from a users id using powershell</p>
  
  <p>The format we use is the first letter of the first name, first four letters of the last name and studentid so a student with the name John Smith with Id# 123456 would be jsmit123456
  the problem I get if the user has less than 4 letters in their name.
  so using substring would give and error for those id's</p>
  
  <p>I tried select-string, -match, trim, trimstart, trimend </p>
  
  <p>here is my code so far </p>
  
  <pre><code>$name = Get-ADUser -SearchBase "OU=A,DC=B,DC=C,DC=edu" 
  -Filter {Created -ge $checktime}     
  |Select-Object SAMAccountName
  
  foreach($object in $name){
  $object
  $studentid = $object.SAMAccountName.Substring(5,6)
  $studentid
  }
  </code></pre>