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_IntroToDsc
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