powershell script

mark 1 Reputation point
2020-11-11T12:53:03.257+00:00

Hello

i have a powerscript below that produces the below,

Get-ADGroup -Filter 'GroupCategory -eq "Security"' -properties members | Select Name, @{name=”Users”;expression={$_.members -join “;”}} | export-csv -NoTypeInformation

im looking to get only the member names

"Class-name-Group","CN=Name 1,OU=Name of OU,OU=Name of OU OU=site,DC=site name,DC=site name,DC=site name;CN=name of user 2,OU=Name of OU,OU=Name of OU,OU=site name,DC=site name,DC=site name,DC=site;

Therefore is there a way using say -replace or -split to get as below, name of the group followed by just the names, even removing the CN=

"Class-name-Group","CN=Name 1;CN=name of user 2"

Many Thanks

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,521 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. SChalakov 10,386 Reputation points MVP
    2020-11-11T13:42:31.33+00:00

    Hi Mark,

    If I get this right you want to have the Display Names of the group members? Is that correct? If so, why not just using it like that:

    (Get-ADGroup -Filter 'GroupCategory -eq "Security"' -properties members | Get-ADGroupMember).name
    

    Not quite sure what your exact goal is, so a bit more information would help.

    Thnaks and Regards,
    Stoyan

    0 comments No comments

  2. mark 1 Reputation point
    2020-11-11T13:46:36.89+00:00

    Hi Yes would like the Group name and then the group members, with my current script it is listing the full path of the members (having there CN=, and OU =

    I would so it does not cn= and Ou=
    Hope that makes more sense
    thanks


  3. mark 1 Reputation point
    2020-11-11T14:33:15.233+00:00

    Thanks, However as per you output for the GroupMembers i only want it to say the name like Joe Bloggs is in the Administator group. as per your example its showing the full path to where the object is.

    Does that make sense?

    0 comments No comments

  4. mark 1 Reputation point
    2020-11-11T14:58:06.997+00:00

    i posted the same question on another forum and somethere has given me the answer

    Get-ADGroup -Filter 'GroupCategory -eq "Security"' -properties members |
    Select Name, @{name=”Users”;expression={ ($_.members -ireplace 'CN=(?<User>[^,]).','${User}' )-join “;”}} |
    export-csv -NoTypeInformation

    Many Thank you for your help

    0 comments No comments

  5. Ian Xue 36,751 Reputation points Microsoft Vendor
    2020-11-12T06:23:47.04+00:00

    Hi,

    Thank you for sharing the solution. Please "Accept Answer" to help other community members find the helpful reply quickly.

    Best Regards,
    Ian

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.