Skip to content
dscbot edited this page Nov 11, 2023 · 1 revision

xGroupSet

Parameters

Parameter Attribute DataType Description Allowed Values
GroupName Required System.String[] An array of the names of the groups to configure.
Ensure Write System.String Specifies whether or not the set of groups should exist.

Set this property to Present to create or modify a set of groups. Set this property to Absent to remove a set of groups. | Present, Absent | | MembersToInclude | Write | System.String[] | The members that should be included in each group in the set. | | | MembersToExclude | Write | System.String[] | The members that should be excluded from each group in the set. | | | Credential | Write | System.Management.Automation.PSCredential | The credential to resolve all groups and user accounts. | |

Description

Provides a mechanism to configure and manage multiple xGroup resources with common settings but different names

Examples

Example 1

#Requires -Module xPSDesiredStateConfiguration

<#
    .SYNOPSIS
        Configuration that add members to multiple groups.

    .DESCRIPTION
        Configuration that add members to multiple groups and make sure the users
        are added back as members of the groups if they are ever removed.

        If a group does not exist, the group is created and the members are added.

    .PARAMETER Name
        The name of one or more groups to add members to.

    .PARAMETER MembersToInclude
        One or more usernames of the users that should be added as members of the
        group.

    .EXAMPLE
        xGroupSet_AddMembersConfig -Name @('Administrators', 'GroupName1') -Members @('Username1', 'Username2')

        Compiles a configuration that adds the users that have the usernames
        'Username1' and 'Username2' to each of the groups 'GroupName1' and
        'Administrators'.
        If the groups named 'GroupName1' or 'Administrators' do not exist, creates
        the groups named 'GroupName1' and 'Administrators' and adds the users
        with the usernames 'Username1' and 'Username2' to both groups.

    .EXAMPLE
        Start-AzureRmAutomationDscCompilationJob -ResourceGroupName '<resource-group>' -AutomationAccountName '<automation-account>' -ConfigurationName 'xGroupSet_AddMembersConfig' -Parameters @{ Name = @('Administrators', 'GroupName1'); Members = @('Username1', 'Username2') }

        Compiles a configuration in Azure Automation that adds the users that
        have the usernames 'Username1' and 'Username2' to each of the groups
        'GroupName1' and 'Administrators'.
        If the groups named 'GroupName1' or 'Administrators' do not exist, creates
        the groups named 'GroupName1' and 'Administrators' and adds the users
        with the usernames 'Username1' and 'Username2' to both groups.

        Replace the <resource-group> and <automation-account> with correct values.
#>
Configuration xGroupSet_AddMembersConfig
{
    param
    (
        [Parameter(Mandatory = $true)]
        [System.String[]]
        $Name,

        [Parameter()]
        [System.String[]]
        $MembersToInclude
    )

    Import-DscResource -ModuleName 'xPSDesiredStateConfiguration'

    Node localhost
    {
        xGroupSet 'AddMembers'
        {
            GroupName        = $Name
            Ensure           = 'Present'
            MembersToInclude = $MembersToInclude
        }
    }
}