Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3877832
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:32:36+00:00 2026-05-19T22:32:36+00:00

Working with Active Directory export script. Currently, the script easily exports user objects from

  • 0

Working with Active Directory export script. Currently, the script easily exports user objects from a given group into a .txt file as fully qualified names (ie. instead of reporting as “username”, you get the ugly “CN=username,OU=foo,OU=bar,DC=foo,DC=bar”).

My Powershell experience is novice at best. What I’ve gotten so far:

  • load contents of text file
  • split contents of text file at the “,”
  • write these contents into a second text file.

  • resulting text file looks like this:

    "CN=username  
    OU=foo  
    OU=bar  
    DC=foo  
    DC=bar"
    

My goal:

  • Save any resulting line of text that begins with “CN= (yes I’d like to keep that ” at the beginning)
  • Delete everything else
  • Strip “CN= from the beginning of the resulting lines
  • Note: usernames vary in length

What I have so far:

$a = (Get-Content c:\test.txt | foreach-Object {$_.split(",,") })  
Out-File c:\results.txt -inputObject $a

I’m completely lost as to how to search text files for a pattern with a wildcard (ie. seach for any lines that contain “CN=* and keep those lines and those lines only) and then stick the results into a .txt.

Thank you so much for any and all guidance you might provide.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:32:37+00:00Added an answer on May 19, 2026 at 10:32 pm

    Select-String would allow that. It’s kinda grep for PowerShell.

    However, if I understand you correctly you can do that a bit easier with

    $a = (Get-Content c:\test.txt | foreach-Object {$_.split(",,") }) -match '^CN='
    

    The comparison operators can be applied to a list of objects and return only the matching items.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so i'm trying to pull a user from active directory into a DirectoryUser
I am currently working on a PHP script that will be polling Active Directory
How to enable user account in Active Directory from Perl if that account is
In our system we are reading user security groups from an Active Directory in
I'm working on importing groups and users from active directory using sql server. I've
Has anyone seen any solid libraries for working with active directory (mainly user related
How are you integrating Active Directory objects (users, groups, etc) into your DDD .NET
I'm working on taking a date value (createWhen) from Active Directory, and translating it
I am working with Active Directory using C#. Instantiating the PrincipalContext object seems to
I have code which as been working against an older Active Directory server and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.