forked from dsccommunity/xPSDesiredStateConfiguration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxGroup_SetMembersConfig.ps1
86 lines (72 loc) · 3.06 KB
/
xGroup_SetMembersConfig.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
84
85
86
<#PSScriptInfo
.VERSION 1.0.1
.GUID 8662bf80-5818-463b-8954-daf8a79525e7
.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 make sure a group exist and have the correct members.
.DESCRIPTION
Configuration that make sure a group exist and have the correct members.
If the group does not exist, adds the users and make sure the members of
the group are only those that are in the configuration. If the group
already exists and if there are any members not in the configuration,
those members will be removed from the group, and any missing members
that are in the configuration will be added to the group.
.PARAMETER Name
The name of the group to create or/and add members to.
.PARAMETER Members
One or more usernames of the users that should be the only members of the
group.
.EXAMPLE
xGroup_SetMembersConfig -Name 'GroupName1' -Members @('Username1', 'Username2')
Compiles a configuration that creates the group 'GroupName1, if it does
not already exist, and adds the users with the usernames 'Username1'
and 'Username2' to the group. If the group named GroupName1 already
exists, removes any users that do not have the usernames Username1 or
Username2 from the group and adds the users that have the usernames
Username1 and Username2 to the group.
.EXAMPLE
Start-AzureRmAutomationDscCompilationJob -ResourceGroupName '<resource-group>' -AutomationAccountName '<automation-account>' -ConfigurationName 'xGroup_SetMembersConfig' -Parameters @{ Name = 'GroupName1'; Members = @('Username1', 'Username2') }
Compiles a configuration in Azure Automation that creates the group
'GroupName1, if it does not already exist, and adds the users with the
usernames 'Username1' and 'Username2' to the group.
If the group named GroupName1 already exists, removes any users that do
not have the usernames Username1 or Username2 from the group and adds
the users that have the usernames Username1 and Username2 to the group.
Replace the <resource-group> and <automation-account> with correct values.
#>
Configuration xGroup_SetMembersConfig
{
param
(
[Parameter(Mandatory = $true)]
[System.String]
$Name,
[Parameter()]
[System.String[]]
$Members
)
Import-DscResource -ModuleName 'xPSDesiredStateConfiguration'
Node localhost
{
xGroup 'SetMembers'
{
GroupName = $Name
Ensure = 'Present'
Members = $Members
}
}
}