title: Powershell Pipe to Switch Statement to format a phone number
body: <p>I am attempting to query AD to get the phone number for a user then format it to a standard format (###-####).  I'm using a Switch statement because I've seen the number in a handful of different formats. With the way I have my code set up though I am getting an error: "The term Switch is not recognized as a name of a cmdlet, function, script file..."</p>
  
  <p>Here's the code:</p>
  
  <pre><code>$ADInfo = Get-ADUser $User.Email.split("@")[0] -Properties * -Server $DC
  $User.'Phone Number' = $ADInfo.telephoneNumber | Switch -regex ($_) {
      '^\d{5}$'                     
      {                        
          "{0:38#-####}" -f $_
          break
      }
      '^\d{7}$' 
      {
          "{0:###-####}" -f $_
          break
      }
      default
      {
          break
      } 
  
  }
  </code></pre>
  
  <p>Am I misunderstanding how the pipeline works? I suppose I could just save this info to a temp variable and then enter a Switch statement but this seemed like an effective way to use the pipeline.  </p>
  
  <p>Anyhow, any help is appreciated! Thanks!</p>