-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsad.ps1
65 lines (54 loc) · 1.59 KB
/
sad.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
#############################################################################
# #
# name: sad.ps1 #
# script version 0.9 #
# #
# author: edi #
# #
# comment: search ad #
# #
# 20.02.2013 :: release #
# #
#############################################################################
import-module activedirectory
function getclients
{
$n = 0
$f = "(objectclass=computer)"
$srch = new-object system.directoryservices.directorysearcher
$srch.filter = $f
#$dsn = get-addomain | select -expand distinguishedname
$srch.searchroot = "LDAP://dc=asp,dc=t,dc=univie,dc=ac,dc=at"
#$srch.searchroot = "LDAP://$dsn"
$clients = $srch.findall()
foreach ($client in $clients)
{
$prop = $client.properties
$cname = $prop.name
"$cname"
$n++
}
write-host "....$n computer objects found"
}
function getusers
{
$f = "(objectcategory=user)"
$srch = new-object system.directoryservices.directorysearcher
#$dsn = get-addomain | select -expand distinguishedname
$srch.searchroot = "LDAP://dc=t,dc=univie,dc=ac,dc=at"
$srch.filter = $f
$users = $srch.findall()
foreach ($user in $users)
{ $prop = $user.properties
$prop.samaccountname
}
}
write-host "`t`tpress 1 - ad users" -foregroundcolor cyan
write-host "`t`tpress 2 - ad clients" -foregroundcolor cyan
$whatsup = read-host
switch ($whatsup)
{
1 {getusers}
2 {getclients}
default {write-host "only [1,2]"}
}