Trim with Powershell

Posted on 2015-01-23
Medium Priority
Last Modified: 2015-01-23
I am trying to return the groups that a user is part of. When I get the results, often there is extra spaces to the right of the results. I would like to trim those off. Is there a way to use trim() functionality for the following line?

Get-ADPrincipalGroupMembership <user> | select name
Question by:stakor
LVL 18

Accepted Solution

Learnctx earned 2000 total points
ID: 40566231
You will need to do one of the following.

Get-ADPrincipalGroupMembership <user> | Select -Expand Name | Foreach-Object {$_.trim()}


Get-ADPrincipalGroupMembership <user> | Select @{name="Name";Expression={($_.name).trim()}}

Author Closing Comment

ID: 40566237
Works wonderfully.

Featured Post

Managed Security Services Webinar - March 15

Selecting the right managed security services platform to grow your business can be a huge undertaking. Join WatchGuard and Frost & Sullivan in an upcoming webinar as we dive into the key elements of selecting a vendor platform and partnership to fuel a successful MSSP business.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
The PowerShell Core 6.0 of .NET release is just the beginning. The upcoming PowerShell Core 6.1 would have artificial intelligence and internet of things capabilities. So many things to look forward to in the upcoming release.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question