Get-SympaMailingListMember.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function Get-SympaMailingListMember
{

<#
.Synopsis
   This function returns the members of a Mailing list(s)
.EXAMPLE
   Get-SympaMailingListMember -Sympa $Sympa -MailingList queens-it
.EXAMPLE
   Get-SympaMailingListMember -Sympa $Sympa -MailingList @('queens-it','queens-undergrads')
#>


param(

    [Parameter(Mandatory=$true,HelpMessage="Pass in the result of the 'Get-SympaLogin' function")]
    $Sympa,
    [Parameter(Mandatory=$true,HelpMessage="Enter the name of the Mailing list(s) you want to return the member(s) of",ValueFromPipelineByPropertyName=$True)]
    [Array]$MailingList

    )
    
    #Create empty collection
    $Output = New-Object System.Collections.ArrayList

    #Loop over the mailing lists provided
    foreach($MailList in $MailingList){
        
        $Results = $Sympa.review("$MailList")

        #Parse the list into objects (Sympa only returns a big long string with line breaks)
        foreach($Result in $Results){

            #Build an object to store the results in
            $Item = New-Object -TypeName System.Object

            #Add the members to the object
            $Item | Add-Member -MemberType NoteProperty -Name "MailingList" -Value $MailList
            $Item | Add-Member -MemberType NoteProperty -Name "Member" -Value $Result

            #Add the object to the collection
            $Output.Add($Item) | Out-Null
        }
    }

    #Return the output as a Collection
    Return $Output
}