Last active
          October 23, 2018 13:51 
        
      - 
      
- 
        Save mattmcnabb/223ff8d3dd2ec75c65514aec3c535bee to your computer and use it in GitHub Desktop. 
    Add a Truncate method to system.string
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | $Script = { | |
| param([int]$MaxLength) | |
| switch ($this) | |
| { | |
| {[string]::IsNullOrEmpty($_)} {$this; break} | |
| {$_.Length -le $MaxLength} {$this; break} | |
| default {$_.SubString(0, $MaxLength)} | |
| } | |
| } | |
| $TypeDataSplat = @{ | |
| TypeName = 'System.String' | |
| MemberType = 'ScriptMethod' | |
| MemberName = 'Truncate' | |
| Value = $Script | |
| } | |
| Update-TypeData @TypeDataSplat -Force | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment