Skip to content

Commit

Permalink
Adding a peoplestage function to get lists for #13
Browse files Browse the repository at this point in the history
  • Loading branch information
gitfvb committed Jul 1, 2024
1 parent 133b728 commit 947d04c
Showing 1 changed file with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@


function Get-Groups {
[CmdletBinding()]
param (
[Parameter(Mandatory=$false)][Hashtable] $InputHashtable
#[Parameter(Mandatory=$false)][Switch] $DebugMode = $false
)

begin {


#-----------------------------------------------
# LOG
#-----------------------------------------------

$moduleName = "GETGROUPS"

# Start the log
Write-Log -message $Script:logDivider
Write-Log -message $moduleName -Severity INFO

# Log the params, if existing
Write-Log -message "INPUT:"
if ( $InputHashtable ) {
$InputHashtable.Keys | ForEach-Object {
$param = $_
Write-Log -message " $( $param ) = '$( $InputHashtable[$param] )'" -writeToHostToo $false
}
}

#-----------------------------------------------
# DEPENDENCIES
#-----------------------------------------------

#Import-Module MeasureRows
#Import-Module SqlServer
#Import-Module ConvertUnixTimestamp
#Import-Lib -IgnorePackageStructure

}

process {

# Load mailings data from CleverReach
$groups = Get-List -Type STANDARD

Write-Log "Loaded $( $groups.Count ) groups from Inxmail" -severity INFO

# Load and filter list into array of mailings objects
$groupsList = [System.Collections.ArrayList]@()
$groups | ForEach-Object {
$group = $_
[void]$groupsList.add(
[MailingList]@{
mailingListId=$group.id
mailingListName=( $group.name -replace '[^\w\s]', '' )
}
)
}

# Transform the mailings array into the needed output format
$columns = @(
@{
name="id"
expression={ $_.mailingListId }
}
@{
name="name"
expression={ $_.toString() }
}
)

$lists = [System.Collections.ArrayList]@()
[void]$lists.AddRange(@( $groupsList | Select-Object $columns ))

If ( $lists.count -gt 0 ) {

Write-Log "Loaded $( $lists.Count ) lists/groups" -severity INFO #-WriteToHostToo $false

} else {

$msg = "No lists loaded -> please check!"
Write-Log -Message $msg -Severity ERROR
throw $msg

}

# Return
$lists

}

end {

}

}

0 comments on commit 947d04c

Please sign in to comment.