My most useful 8 liner yet

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

Function Split-N-Trim {
      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

Have a code issue? Share your code by going to and pasting your code there, then post the link here!

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.