none
Format CSV Tables after AD Groups Members Extraction

    Вопрос

  • Hi

    I am writing another question as I can't seem to work it out as yet. What happens is I am trying to display all the Members in a Team from the AD.

    Take for an example a soccer group table.

    GroupA consists of Team1, Team2, Team3

    GroupB consists of Team4, Team5, Team6

    GroupC consists of Team7, Team8, Team9

    I would like to generate a script so that it will export out all the details to a csv. Format should look like below

    Group Team Description DisplayName
    Group A Team1 Team One Player 1
    Group A Team1 Team One Player 2
    Group A Team1 Team One Player 3
    Group A Team1 Team One Player 4
    Group A Team2 Team Two Player 1
    Group A Team2 Team Two Player 2
    Group A Team2 Team Two Player 3
    Group A Team2 Team Two Player 4


    I have got a code which I got from previous forum but I don't seem to get the desired output. Here is the code

    Add-PSSnapin Quest.ActiveRoles.ADManagement
    #Set-QADPSSnapinSettings -DefaultSizeLimit 0

    $Results
    = @()
    $Output
    = "C:\TeamPlayers.csv"
    #Clear-Content $Output
    $Group
    = Get-QADGroup GroupA
    ForEach ($Team in $Group) {
    $Results
    += Get-QADGroupMember $Team |
    Add-Member -Name "Team" -Value $Team -MemberType NoteProperty -PassThru |
    Select Team,Description,DisplayName
    }

    # Output results in selected format
    $Results
    | Export-CSV -Path $Output -NoTypeInformation

    And I got this output

    Team Description DisplayName
    Group A Team One Team1
    Group A Team Two Team2
    Group A Team Three Team3
    Any idea what went wrong? I am new to Powershell

    Thanks

    8 марта 2012 г. 2:12

Ответы

  • $Groups = "GroupA","GroupB","GroupC" | Get-QADGroup 
    ForEach ($Team in $Groups) { 
    	$Teams = Get-QADGroupMember $Team
    	Foreach ($GTeam in $Teams)
    	{
    		$Players = Get-QADGroupMember $GTeam
    		ForEach ($Player in $Players)
    		{
    			$Results += New-Object PsObject -Property @{
    			Group = $Team.Name
    			Team  = $GTeam.Name
    			Description = $T.Description
    			DisplayName = $Player.DisplayName
    			} | Select Group,Team,Description,DisplayName
    		}
    	}
    }
    $Results | Sort Team,DisplayName | Export-CSV -Path $Output -NoTypeInformation

    • Изменено KazunMVP 8 марта 2012 г. 8:56
    • Помечено в качестве ответа cyw77 8 марта 2012 г. 23:24
    8 марта 2012 г. 8:52

Все ответы

  • $Groups = "GroupA","GroupB","GroupC" | Get-QADGroup 
    ForEach ($Team in $Groups) { 
    	$Teams = Get-QADGroupMember $Team
    	Foreach ($GTeam in $Teams)
    	{
    		$Players = Get-QADGroupMember $GTeam
    		ForEach ($Player in $Players)
    		{
    			$Results += New-Object PsObject -Property @{
    			Group = $Team.Name
    			Team  = $GTeam.Name
    			Description = $T.Description
    			DisplayName = $Player.DisplayName
    			} | Select Group,Team,Description,DisplayName
    		}
    	}
    }
    $Results | Sort Team,DisplayName | Export-CSV -Path $Output -NoTypeInformation

    • Изменено KazunMVP 8 марта 2012 г. 8:56
    • Помечено в качестве ответа cyw77 8 марта 2012 г. 23:24
    8 марта 2012 г. 8:52
  • Hi Kazun

    Thanks for solving that for me.

    One more question say if we need to display the Notes information for the Team, would it be $T.Notes?

    Also as I am new to Powershell, what is $T.xxx as I did see it declared in any place. How did you work out what was $T and that would contain the Description of the Team?


    Thanks


    • Изменено cyw77 8 марта 2012 г. 23:58
    8 марта 2012 г. 23:33
  • $Results += New-Object PsObject -Property @{
    			Group = $Team.Name
    			Team  = $GTeam.Name
    			Description = $GTeam.Description
    			DisplayName = $Player.DisplayName
    			Notes = $GTeam.Notes
    			} | Select Group,Team,Notes,Description,DisplayName

    $T - it's a my mistake,$T must be replace on the $GTeam.
    • Изменено KazunMVP 9 марта 2012 г. 6:38
    9 марта 2012 г. 6:37