title: Using a function in a calculated field in Powershell?
body: <p>So I have this:</p>
  
  <pre><code>get-ADUser -SearchRoot 'boogers.com/Locations/Kleenex' | 
  Where-Object { $_.TITLE -ne 'Snot' } | 
  Select LastName,FirstName,Description,SamAccountName,Department,TITLE, @{Name='bs_value';Expression=@{Name='TITLE'; Expression={(Get-Culture).TextInfo.ToTitleCase($_.Title.ToLower())}}
  </code></pre>
  
  <p>And it works great, until, oh I dunno, I want another calculated field...then it becomes <strong>JUST TOO LONG!</strong></p>
  
  <p>So I write a function:</p>
  
  <pre><code>function tc($name, $str) {
      return @{Name=$name; Expression={(Get-Culture).TextInfo.ToTitleCase($str.ToLower())}}
  }
  </code></pre>
  
  <p>Seems reasonable enough, no?</p>
  
  <p>But if I run the function:</p>
  
  <pre><code>$bob = tc 'Title' 'bob'
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>Name                           Value
  ----                           -----
  Expression                     (Get-Culture).TextInfo.ToTitleCase($str.ToLower())
  Name                           Title
  </code></pre>
  
  <p>Instead of...</p>
  
  <pre><code>Name                           Value
  ----                           -----
  Expression                     "Bob"
  Name                           Title
  </code></pre>
  
  <p>I just want the code to be shorter!  I'm using a computer!</p>