-
Notifications
You must be signed in to change notification settings - Fork 98
/
checkgroupDN.ps1
45 lines (38 loc) · 1004 Bytes
/
checkgroupDN.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
######################################################################################
Param(
[string]$Group
)
function checkgroupDN ($Group)
{
$Search = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$Search.filter = "(&(objectCategory=group)(objectClass=group)(sAMAccountName=$Group))"
$findgrp=$Search.Findall()
if ($findgrp.count -gt 1)
{
$count = 0
foreach($i in $findgrp)
{
write-host $count ": " $i.path
$count = $count + 1
write-host "multiple matches found"
}
exit
}
elseif ($findgrp.count -gt 0)
{
return $findgrp[0].path
}
else
{
write-host "no match found"
}
}
if($Group -like $null)
{
"Pls use script as - checkgroupDN.ps1 groupsamacountname"
}
else
{
checkgroupDN $Group
}
###################################################################################