-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathRemoveUnknownACLs.ps1
65 lines (62 loc) · 2.24 KB
/
RemoveUnknownACLs.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
Import-Module JAMS
# The following script checks all Jobs, Variables and Folders (except root \ folder)
# for the presense of an <unknown> ACE (in the Security tab) and removes it.
#
New-PSDrive JD JAMS localhost -ErrorAction SilentlyContinue
$folders = Get-ChildItem JD:\ -ObjectType folder -Recurse -IgnorePredefined
foreach($folder in $folders){
$folder.QualifiedName
$objs = Get-ChildItem "JD:$($folder.QualifiedName)"
#
# Loop through all jobs and variables within the folder
#
foreach ($item in $objs)
{
$jobVarUpdated = $false;
$jobVar = Get-Item "JD:\$($item.QualifiedName)"
for($i = $jobVar.Acl.GenericACL.Count - 1; $i -ge 0; $i--)
{
# Get the ACE at the current index
$ace = $jobVar.Acl.GenericACL[$i]
#
# Check if this ACE is the one want we want to remove and is not inherited
#
if (!($ace.Inherited) -AND $ace.Identifier.ToLower() -eq "<unknown>") #
{
Write-Host "Removed from Job or Variable: " $jobVar.QualifiedName
# Remove the ACE from the collection
$jobVar.Acl.GenericACL.Remove($ace)
$jobVarUpdated = $true;
}
}
if($jobVarUpdated)
{
$jobVar.Update()
}
}
#
# Now check the Folder itself
#
$folderUpdated = $false;
$thisFolder=Get-Item "JD:$($folder.QualifiedName)"
for($i = $thisFolder.Acl.GenericACL.Count - 1; $i -ge 0; $i--)
{
# Get the ACE at the current index
$ace = $thisFolder.Acl.GenericACL[$i]
#
# Check if this ACE is the one want we want to remove and is not inherited
#
if (!($ace.Inherited) -AND $ace.Identifier.ToLower() -eq "<unknown>") #
{
Write-Host "Removed from Folder: " $thisFolder.QualifiedName
# Remove the ACE from the collection
$thisFolder.Acl.GenericACL.Remove($ace)
$folderUpdated = $true;
}
}
if($folderUpdated)
{
$thisFolder.Update()
}
}
Remove-PSDrive JD