Debian Codegraph @

ansible_collections/microsoft/ad/plugins/modules/group.ps1

raw
1 #!powershell
2
3 # Copyright: (c) 2023, Ansible Project
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 #AnsibleRequires -CSharpUtil Ansible.Basic
7 #AnsibleRequires -PowerShell ..module_utils._ADObject
8
9 $setParams = @{
10 PropertyInfo = @(
11 [PSCustomObject]@{
12 Name = 'category'
13 Option = @{
14 choices = 'distribution', 'security'
15 type = 'str'
16 }
17 Attribute = 'GroupCategory'
18 CaseInsensitive = $true
19 }
20 [PSCustomObject]@{
21 Name = 'homepage'
22 Option = @{ type = 'str' }
23 Attribute = 'Homepage'
24 }
25 [PSCustomObject]@{
26 Name = 'managed_by'
27 Option = @{ type = 'str' }
28 Attribute = 'ManagedBy'
29 DNLookup = $true
30 }
31 [PSCustomObject]@{
32 Name = 'members'
33 Option = @{ type = 'add_remove_set' }
34 Attribute = 'member'
35 DNLookup = $true
36 IsRawAttribute = $true
37 # If the group is part of the CN=Builtin groups, it cannot
38 # use -Replace. This ensures it always uses -Add/-Remove when
39 # setting a changed value to handle this.
40 # https://github.com/ansible-collections/microsoft.ad/issues/130
41 SupportsReplace = $false
42 }
43 [PSCustomObject]@{
44 Name = 'sam_account_name'
45 Option = @{ type = 'str' }
46 Attribute = 'sAMAccountName'
47 }
48 [PSCustomObject]@{
49 Name = 'scope'
50 Option = @{
51 choices = 'domainlocal', 'global', 'universal'
52 type = 'str'
53 }
54 Attribute = 'GroupScope'
55 CaseInsensitive = $true
56 }
57 )
58 ModuleNoun = 'ADGroup'
59 DefaultPath = {
60 param($Module, $ADParams)
61
62 $GUID_USERS_CONTAINER_W = 'A9D1CA15768811D1ADED00C04FD8D5CD'
63 $defaultNamingContext = (Get-ADRootDSE @ADParams -Properties defaultNamingContext).defaultNamingContext
64
65 Get-ADObject @ADParams -Identity $defaultNamingContext -Properties wellKnownObjects |
66 Select-Object -ExpandProperty wellKnownObjects |
67 Where-Object { $_.StartsWith("B:32:$($GUID_USERS_CONTAINER_W):") } |
68 ForEach-Object Substring 38
69 }
70 PreAction = {
71 param ($Module, $ADParams, $ADObject)
72
73 if ($Module.Params.state -eq 'present' -and (-not $Module.Params.scope) -and (-not $ADObject)) {
74 $Module.FailJson("scope must be set when state=present and the group does not exist")
75 }
76 }
77 PostAction = {
78 param($Module, $ADParams, $ADObject)
79
80 if ($ADObject) {
81 $Module.Result.sid = $ADObject.SID.Value
82 }
83 elseif ($Module.Params.state -eq 'present') {
84 # Use dummy value for check mode when creating a new user
85 $Module.Result.sid = 'S-1-5-0000'
86 }
87 }
88 }
89 Invoke-AnsibleADObject @setParams