Office365-Scoutnet-synk

Synkronisering av användarkonton och e-postlistor från Scoutnet till Office 365


Project maintained by Scouterna Hosted on GitHub Pages — Theme by mattgraham

Update-SNMicrosoft365Group

Synchronizes configured Microsoft 365 group memberships with Scoutnet.

Description

Only groups explicitly configured in Microsoft365GroupSettings are managed. Other groups are never read for changes or modified.

Microsoft365GroupSettings is a hashtable where each key is the group display name and each value is a rule with these entries:

Required for all rules mail_nickname Unique mail nickname, used when the group is created. Optional for all rules source ‘mail_list’, ‘troop_roles’ or ‘group_roles’. Omit to manage only keep_members without a Scoutnet connection. description Group description, used when the group is created. group_type ‘microsoft365’ (default) for a Microsoft 365 group, or ‘security’ for a security group (not mail enabled). Security groups can be used to control access, for example to a SharePoint area. They cannot be teams. create_team Set to $true to also make the group a Microsoft Teams team. keep_members Accounts (user principal names or object ids) to add to the group and never remove. Required when source is omitted. team_owners Owners (user principal names or object ids) added to the group when the team is created. Teams requires the group to have an owner.

source = ‘mail_list’ (membership from a Scoutnet maillist) scoutnet_list_id Required. Id of the list in Scoutnet. member_type Optional. ‘ledare’ (default), ‘scouter’ or ‘both’. statisk_lista Optional. Set for static Scoutnet lists.

source = ‘group_roles’ (roles on the scout group) roles Required. Role names, for example ‘Kårledare’. One match is enough. Use ‘*’ to match every member with any role on the scout group.

source = ‘troop_roles’ (roles in one or more troops) troops Required. A list of rules, each with ‘roles’ and ‘name’ and/or ‘id’. Add unit_members = $true to also include the members of that troop (the member’s ‘unit’); ‘roles’ is then optional. The troop name is matched first and the troop id is the fallback. Use roles = ‘*’ to match every member with any role in that troop.

The function validates all rules first, fetches the member list, the maillists and the Exchange mailboxes, and only then changes Microsoft 365. A member is mapped to an account through the mailbox CustomAttribute1, which holds the Scoutnet member number. A member matching a rule without an account, for example a leader too young for an own account, is written to the log and skipped.

For each rule the group is created as a Microsoft 365 (Unified) group, or as a security group when group_type is ‘security’, if it does not exist. Matching accounts missing in the group are added and members that no longer match, for example leaders whose account was closed or who left the troop, are removed. Accounts listed in keep_members are added and never removed. When source is omitted, the group is managed only from keep_members and no Scoutnet data is fetched. Owners are also never removed, which protects an existing team whose owners are not part of the rule. Existing groups of another type than configured, or display names that are not unique, cause an error and the group is not changed.

When create_team is $true the group is made a Teams team after its membership has been synchronized, unless it already is a team. A team is never removed or changed if create_team is omitted. Creating teams needs the Microsoft.Graph.Teams module (New-MgTeam) and the Team.Create permission. If the group is new, creating the team is retried a few times because Teams can take a while to see a new group.

Syntax

Update-SNMicrosoft365Group [[-Configuration] <Object>] [-WhatIf] [-Confirm] [<CommonParameters>]

Parameters

-Configuration

Type: Object; optional.

Configuration to use. If omitted, the cached module configuration is used. A supplied configuration also becomes the cached configuration.

Examples

Example 1

$conf.Microsoft365GroupSettings = @{
    'Styrelsen' = @{
        source        = 'group_roles'
        mail_nickname = 'styrelsen'
        roles         = @('Ordförande', 'Kassör', 'Utmanarscoutrepresentant')
        create_team   = $true
        team_owners   = @('admin@example.org')
    }
}
Update-SNMicrosoft365Group -Configuration $conf

Example 2

$conf.Microsoft365GroupSettings = @{
    'Avdelningsledare Äventyrarna' = @{
        source        = 'troop_roles'
        mail_nickname = 'avdelningsledare-aventyrarna'
        troops        = @(@{ name = 'Äventyrarna'; id = '2'; roles = @('Avdelningsledare', 'Ledare') })
    }
}
Update-SNMicrosoft365Group -Configuration $conf -WhatIf

Example 3

$conf.Microsoft365GroupSettings = @{
    'Alla ledare Äventyrarna' = @{
        source        = 'troop_roles'
        mail_nickname = 'alla-ledare-aventyrarna'
        troops        = @(@{ name = 'Äventyrarna'; id = '2'; roles = '*' })
    }
}
Update-SNMicrosoft365Group -Configuration $conf

Example 4

$conf.Microsoft365GroupSettings = @{
    'Säkerhet Spårarledare' = @{
        source        = 'troop_roles'
        group_type    = 'security'
        mail_nickname = 'sakerhet-sparar-ledare'
        troops        = @(@{ name = 'Spårarna'; roles = '*' })
    }
}
Update-SNMicrosoft365Group -Configuration $conf

Example 5

$conf.Microsoft365GroupSettings = @{
    'Extern arbetsgrupp' = @{
        mail_nickname = 'extern-arbetsgrupp'
        keep_members  = @('person@example.org', 'object-id')
    }
}
Update-SNMicrosoft365Group -Configuration $conf