-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeployment_manager_groups.ps1
52 lines (45 loc) · 1.71 KB
/
deployment_manager_groups.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
#$username=$Env:USERNAME
$username='prinzu6'
$groups=@{}
$gc="GC://" + $([adsi] "LDAP://RootDSE").Get("RootDomainNamingContext")
$filter = "(&(objectCategory=User)(|(cn=" + $username + ")(samaccountname=" + $username + ")(displayName=" + $username + ")(distinguishedName=" + $username + ")))"
$domain = New-Object System.DirectoryServices.DirectoryEntry($gc)
$searcher = New-Object System.DirectoryServices.DirectorySearcher
$searcher.SearchRoot = $domain
$searcher.Filter = $filter
$results = $searcher.FindAll()
if($results.count -eq 0){ "User Not Found"; }else{
foreach ($result in $results){
$user=$result.GetDirectoryEntry();
$user.GetInfoEx(@("tokenGroups"),0)
$tokenGroups=$user.Get("tokenGroups")
foreach ($token in $tokenGroups){
$principal = New-Object System.Security.Principal.SecurityIdentifier($token,0)
$group = $principal.Translate([System.Security.Principal.NTAccount])
$groups[$group]=1
}
}
}
$a = @();$b=@();$c=@();$clist=@();$nclist=@();[string]$regex = " ";
$groups.keys |%{if($_ -like "`*deploy`*"){$a+=$_;} }
if($a.count -eq 0){break;}
$a|%{$b+=$_ -split("_");$c+=$b[2];$b=$null;}
$regex="(";
$count=$null;
$c|%{$regex+=$_;if($c.Count-1 -ne $count){$regex+="|";}$count++;}
$regex+=")";
$data = get-content –path $env:path2pclist | where-object { $_.trim() -ne '' }
$data | % { $f = $_.split(','); $clist += $f[0];}
for($i=0; $i -lt $clist.count; $i++){
try{
if($clist[$i] -match $regex){
$nclist+=$clist[$i];
}
}catch{
break
}
}
$path="\\"+$env:empirumserver+"\pub_utils$\"+$username+".csv";
$nclist| % {$_ -replace """", ""} | set-content $path
[Environment]::SetEnvironmentVariable("path2pclist", $path, "Machine")