forked from dsccommunity/xPSDesiredStateConfiguration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxGroupSet_AddMembersConfig.ps1
83 lines (69 loc) · 2.88 KB
/
xGroupSet_AddMembersConfig.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<#PSScriptInfo
.VERSION 1.0.1
.GUID db98d037-c170-43cc-a716-da521731e84f
.AUTHOR Microsoft Corporation
.COMPANYNAME Microsoft Corporation
.COPYRIGHT
.TAGS DSCConfiguration
.LICENSEURI https://github.com/dsccommunity/xPSDesiredStateConfiguration/blob/main/LICENSE
.PROJECTURI https://github.com/dsccommunity/xPSDesiredStateConfiguration
.ICONURI
.EXTERNALMODULEDEPENDENCIES
.REQUIREDSCRIPTS
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES First version.
.PRIVATEDATA 2016-Datacenter,2016-Datacenter-Server-Core
#>
#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
}
}
}