My most useful 8 liner yet

Published August 20, 2014 by FoxDeploy

In my line of work, I’m constantly copying and pasting from e-mails, SharePoint, into PowerShell to do some meaningful work.  This means all day long I’m setting variables equal to paste, then removing blank entries, and then splitting them (because people never say ‘please migrate these computers’ and provide a list like $computers=”compA”,”compB”,”compC”.

I then end up Pasting, and running $variable= Paste, then $variable.Trim().Split(“`n”).  I finally decided to speed things up by making this short little few-liner.  I always forgot whether it was Split-N-Trim or not, so I made an alias for the other way around.

It now has a permanent place within my $PSProfile

```powershell Function Split-N-Trim { param( [Parameter(Mandatory=$True,ValueFromPipeline=$True)][string[]]$Objects) Write-Host ("-Recieved " + $Objects.Count +" objects") $Objects = $Objects.Trim().Split("`n") Write-Host ("Returning " + $Objects.Count +" objects") Return $Objects } new-alias Trim-N-Split Split-N-Trim


Microsoft MVP

Five time Microsoft MVP, and now I work for the mothership

Need Help?

Get help much faster on our new dedicated Subreddit!

depicts a crowd of people in a night club with colored lights and says 'join the foxdeploy subrreddit today'

Blog Series
series_sml_PowerShellGUI series_sml_IntroToRaspberryPi Programming series_sml_IntroToWindows Remote Management Series The Logo for System Center Configuration Manager is displayed here Depicts a road sign saying 'Learning PowerShell Autocomplete'

Blog Stats