Group Object multiple paramter Split

Welcome Forums General PowerShell Q&A Group Object multiple paramter Split

Viewing 2 reply threads
  • Author
    Posts
    • #210414
      Participant
      Topics: 12
      Replies: 21
      Points: 135
      Rank: Participant

      Hi Team,

      I am grouping the output in 2 parameter, however the output is mixed up. can this be split for “Name” based on property

      $count=$members |Group-Object -Property objectclass,OU_DN | Select-Object Count, Name
      $count | export-csv c:\temp\oumembersCount.csv -NoTypeInformation

      output ex:

      Count Name
      —– —-
      2409 computer, OU=Test,DC=TEST3, DC=COM
      6027 OU=Test,DC=TEST3, DC=COM
      1776 group, OU=Test2,DC=TEST3, DC=COM
      2557 user, OU=Test2,DC=TEST3, DC=COM
      3411 computer,OU=Test2,DC=TEST3, DC=COM

       

      I want the output as

      Count Name                   OU_DN
      —– —-                    ——————-
      2409 computer     OU=Test,DC=TEST3, DC=COM
      1776 group            OU=Test2,DC=TEST3, DC=COM
      2557 user              OU=Test2,DC=TEST3, DC=COM
      3411 computer    OU=Test2,DC=TEST3, DC=COM

       

    • #210462
      Participant
      Topics: 5
      Replies: 321
      Points: 436
      Helping Hand
      Rank: Contributor
      $count = 
      $members | Group-Object -Property objectclass,OU_DN | 
      Select-Object Count, @{n='Name';exp={$_.Name.split(',',2)[0]}},
      @{n='OU_DN';exp={$_.Name.split(',',2)[1].Trim()}}
      
      $count | export-csv c:\temp\oumembersCount.csv -NoTypeInformation
      
    • #210498
      Participant
      Topics: 12
      Replies: 21
      Points: 135
      Rank: Participant
      PowerShell
      7 lines

      <textarea class=”ace_text-input” style=”opacity: 0; height: 18px; width: 6.59781px; left: 44px; top: 0px;” spellcheck=”false” wrap=”off”></textarea>

      1
      2
      3
      4
      5
      6
      7
      $count =
      $members | Group-Object Property objectclass,OU_DN |
      Select-Object Count, @{n=‘Name’;exp={$_.Name.split(‘,’,2)[0]}},
      @{n=‘OU_DN’;exp={$_.Name.split(‘,’,2)[1].Trim()}}
      $count | export-csv c:\temp\oumembersCount.csv NoTypeInformation
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

      Thanks a lot, that did it. Learning new thing everyday and you guys makes it soo easy.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.