-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathautomation-ADGetComputerGroups.yml
47 lines (47 loc) · 2.01 KB
/
automation-ADGetComputerGroups.yml
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
args:
- description: Active Directory Distinguished Name for the desired computer
name: dn
- description: Name of the desired computer
name: name
- description: Include these AD attributes of the resulting objects in addition to
the default ones
name: attributes
comment: Use Active Directory to retrieve the groups in which the specified computer
is a member. The member computer can be specified by name or by DN.
commonfields:
id: ADGetComputerGroups
version: -1
dependson:
must:
- ad-search
deprecated: true
name: ADGetComputerGroups
runonce: false
script: |-
# Optional arguments and default values
attrs = 'name'
if demisto.get(demisto.args(), 'attributes'):
attrs += "," + demisto.args()['attributes']
memberDN = ''
if demisto.get(demisto.args(), 'dn'):
memberDN = demisto.args()['dn']
elif demisto.get(demisto.args(), 'name'):
resp = demisto.executeCommand('AdSearch', {'filter':"(&(objectCategory=Computer)(name=" + demisto.args()['name']+"))"})
if type(resp)==list and len(resp)==1 and type(resp[0])==dict and 'Contents' in resp[0] and type(resp[0]['Contents'])==list and len(resp[0]['Contents'])==1 and type(resp[0]['Contents'][0])==dict and 'dn' in resp[0]['Contents'][0]:
memberDN = resp[0]['Contents'][0]['dn']
else:
demisto.results( { 'Type' : entryTypes['error'], 'ContentsFormat' : formats['text'], 'Contents' : 'Unexpected output from ad command.' } )
sys.exit(0)
else:
demisto.results( { 'Type' : entryTypes['error'], 'ContentsFormat' : formats['text'], 'Contents' : 'You must provide either dn or name as argument!' } )
sys.exit(0)
if memberDN:
filterstr = r"(&(member=" + memberDN + ")(objectcategory=group))"
demisto.results( demisto.executeCommand( 'AdSearch' , { 'filter' : filterstr, 'attributes' : attrs } ) )
else:
demisto.results( { 'Type' : entryTypes['error'], 'ContentsFormat' : formats['text'], 'Contents' : 'Computer not found.' } )
scripttarget: 0
system: true
tags:
- active directory
type: python