Add members to multiple groups
Description
This example shows how you can use the GroupSet
composite resource to ensure multiple groups exist
and include a specified list of members.
With Ensure set to Present
and GroupName set to an array of Administrators
and
GroupName1
, the resource adds the Administrators
and GroupName1
local groups if they don't
exist.
With MembersToInclude set to an array of Username1
and Username2
, the resource adds
Username1
and Username2
as members to both Administrators
and GroupName1
if they're not
already members.
With Invoke-DscResource
The Invoke-DscResource
cmdlet doesn't support invoking composite resources. Instead, use the
Group resource.
With a Configuration
This snippet shows how you can define a Configuration
with a GroupSet
resource block to ensure
the local groups Administrators
and GroupName1
exist and include Username1
and Username2
as
members.
Configuration AddMembers {
Import-DscResource -ModuleName 'PSDscResources'
Node localhost {
GroupSet GroupSet {
GroupName = @(
'Administrators'
'GroupName1'
)
Ensure = 'Present'
MembersToInclude = @(
'Username1'
'Username2'
)
}
}
}
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for