Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

RFI: Is it possible to use Sub-Attributes and foreach loops in templates? #218

Copy link
Copy link
@Callidus2000

Description

@Callidus2000
Issue body actions

Hi,
I'm developing a template based mail library. As one example I've got the following "data gatherer":

$forest = Get-ADForest
$domains = $forest.Domains

$allUsers = foreach ($domain in $domains) {
    Get-ADUser -Server $domain -Filter "mail -like '*'" -Properties givenName,surname,mail,userPrincipalName |
        Select-Object @{Name='Domain';Expression={$domain}},
                      @{Name='FirstName';Expression={$_.givenName}},
                      @{Name='LastName';Expression={$_.surname}},
                      @{Name='Mail';Expression={$_.mail}},
                      @{Name='UPN';Expression={$_.userPrincipalName}}
}

# Group by mail address and create array with required structure
$userArray = $allUsers | Group-Object -Property Mail | ForEach-Object {
    $firstUser = $_.Group | Select-Object -First 1
    [PSCustomObject]@{
        Mail      = $_.Name
        FirstName = $firstUser.FirstName
        LastName  = $firstUser.LastName
        UserList  = $_.Group
    }
}

I'd like to use a template which creates a mail with a list of all users, but the loop is the problem (see it as pseudo code):

# Hello þFirstNameþ þLastNameþ,

Below you will find a list of your accounts grouped by domain:


## Accounts by Domain
þ{UserList | ForEach-Object {
    "### Domain: $($_.Domain)"
    "- UPN: $($_.UPN)"
} | Join-String -Separator "`n"}þ

Best regards,
Your IT Team

-Sascha aka callidus2000

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.