none
Get members of AD group and their manager, then convert to html, first steps ok, but output not ok yet

    Question

  • Hi,

    I'm trying to get an html page of some teams and their manager.
    Therefore I created a small script

    $Overview = @()
    $Groups = 'GroupA', 'GroupB'
    foreach ($group in $groups){
      $Manager = Get-SamAccountNameUser $((Get-ADUser $Members[0].name -Properties * | select-object manager).manager.split(',')[0]).replace('CN=','')
      $Members = Get-ADGroupMember -Identity $Group | select-object name
      $users = $(foreach ($member in $members){Get-SamAccountNameUser -SamAccountName $member.name})| Sort-Object surname
    
      Write-Host "Manager of $group is $($Manager.GivenName) $($Manager.Surname), members are:" -ForegroundColor Green
      $Users 
      <# if I use pscustomboject I don't get formatting right
    	  $Overview += [PSCustomObject] @{
          Manager = "$($Manager.GivenName) $($Manager.SurName)"
          Users = "$($users.GivenName) $($users.Surname)"
        #>
     }

    It give me:

    Manager of group A is x and users are:
    Manager of group B is y and users are

    Then the list of all users


    Where I would like to have it like this:
    Manager of group A is x and users are: 
    Users
    user1
    User2

    Manager of group B is y and users are: 

    User1
    User2

      To ouput it to an html page.

    Please advise.
    J.

    Jan Hoedt

    Saturday, March 18, 2017 8:43 PM

All replies

  • Here is a starter:

    Get-AdUser -filter "DirectReports -like '*'" -Properties DirectReports |
    ForEach-Object{
    	[pscustomobject]@{ 
    		Manager = $_.Name
    		Users = $_.Directreports
    	} 
    }


    \_(ツ)_/


    • Edited by jrv Saturday, March 18, 2017 9:27 PM
    Saturday, March 18, 2017 9:26 PM
  • Thanks, but actually it's the opposite of what I want.
    Found a script which does what you refer to: https://gallery.technet.microsoft.com/scriptcenter/Get-ADDirectReport-962616c6

    but that needs input of managers to start from.
    I just want to add the groups as input then list the members and the managers of them.


    Jan Hoedt

    Saturday, March 18, 2017 9:59 PM
  • It's a nice approach but I'd have to get the managers first and also their samaccountames whereas with the group to manager & users approach I could just add the groups and manager & users will appear.

    Jan Hoedt

    Saturday, March 18, 2017 10:03 PM
  • You will have to state what it is you are trying to do. ALl you noted was managers and their users in HTML. Please try to ask a clear question without talking about technology or how you think it should be done.  In simple language what are you trying to do?


    \_(ツ)_/

    Saturday, March 18, 2017 10:11 PM
  • I'm trying to get an html page of some teams and their manager.

    So f.e. Get-ADDirectReport -ADGroup GroupA,GroupB, GroupC

    would list

    ManagerofGroupA
    Members

    ManagerofGroupB
    Members

    ManagerofGroupC
    Members


    Jan Hoedt

    Saturday, March 18, 2017 10:14 PM
  • What are reams?  AD does not have teams.


    \_(ツ)_/

    Sunday, March 19, 2017 12:43 AM
  • Indeed, I mean AD Groups, f.e. OurOrganization-Marketing, OurOrganization-IT, OurOrganization-IT-Networking.
    I'd like to quickly show f.e. members of networking team and their manager by executing the powershell script to AD group OurOrganization-IT-Networking

    Jan Hoedt

    Sunday, March 19, 2017 12:28 PM
  • You would use Get-AdGroup and Get-AdGroupMember to do that.


    \_(ツ)_/

    Sunday, March 19, 2017 12:30 PM