@@ -18,16 +18,15 @@ public sealed class GetADEffectiveAccessComand : PSCmdlet, IDisposable
1818
1919 private DirectoryEntryBuilder ? _entryBuilder ;
2020
21- // [ThreadStatic]
22- // private static GuidResolver? _map;
23-
2421 private GuidResolver ? _map ;
2522
2623 [ Parameter (
2724 Position = 0 ,
2825 Mandatory = true ,
26+ ValueFromPipeline = true ,
2927 ValueFromPipelineByPropertyName = true ,
3028 ParameterSetName = IdentitySet ) ]
29+ [ Alias ( "DistinguishedName" , "ObjectGuid" , "ObjectSid" , "SamAccountName" ) ]
3130 public string Identity { get ; set ; } = null ! ;
3231
3332 [ Parameter ( Position = 0 , ParameterSetName = FilterSet ) ]
@@ -82,45 +81,60 @@ protected override void BeginProcessing()
8281 protected override void ProcessRecord ( )
8382 {
8483 if ( _entryBuilder is null ) return ;
85- if ( _map is null ) return ;
8684
87- using DirectoryEntry root = GetRootEntry ( _entryBuilder ) ;
88- using DirectorySearcher searcher = new ( root , LdapFilter , [ SecurityDescriptor ] )
89- {
90- SizeLimit = Top ,
91- Tombstone = IncludeDeletedObjects ,
92- SearchScope = SearchScope ,
93- PageSize = PageSize ,
94- SecurityMasks = SecurityMasks . Group |
95- SecurityMasks . Dacl |
96- SecurityMasks . Owner
97- } ;
98-
99- if ( Audit )
85+ try
10086 {
101- searcher . SecurityMasks |= SecurityMasks . Sacl ;
102- }
87+ using DirectoryEntry root = GetRootEntry ( _entryBuilder ) ;
88+ using DirectorySearcher searcher = new ( root , LdapFilter , [ SecurityDescriptor ] )
89+ {
90+ SizeLimit = Top ,
91+ Tombstone = IncludeDeletedObjects ,
92+ SearchScope = SearchScope ,
93+ PageSize = PageSize ,
94+ SecurityMasks = SecurityMasks . Group |
95+ SecurityMasks . Dacl |
96+ SecurityMasks . Owner
97+ } ;
10398
104- foreach ( SearchResult obj in searcher . FindAll ( ) )
105- {
106- if ( obj . Properties [ SecurityDescriptor ] [ 0 ] is not byte [ ] descriptor )
99+ if ( Audit )
107100 {
108- obj . WriteInvalidSecurityDescriptorError ( this ) ;
109- continue ;
101+ searcher . SecurityMasks |= SecurityMasks . Sacl ;
110102 }
111103
112- AclBuilder builder = new ( obj . Path , descriptor ) ;
113- WriteObject (
114- builder . EnumerateAccessRules ( _map ) ,
115- enumerateCollection : true ) ;
116-
117- if ( Audit )
104+ foreach ( SearchResult obj in searcher . FindAll ( ) )
118105 {
106+ if ( ! obj . Properties . Contains ( SecurityDescriptor ) ||
107+ obj . Properties [ SecurityDescriptor ] [ 0 ] is not byte [ ] descriptor )
108+ {
109+ obj . WriteInvalidSecurityDescriptorError ( this ) ;
110+ continue ;
111+ }
112+
113+ AclBuilder builder = new ( obj . Path , descriptor ) ;
119114 WriteObject (
120- builder . EnumerateAuditRules ( _map ) ,
115+ builder . EnumerateAccessRules ( _map ! ) ,
121116 enumerateCollection : true ) ;
117+
118+ if ( Audit )
119+ {
120+ WriteObject (
121+ builder . EnumerateAuditRules ( _map ! ) ,
122+ enumerateCollection : true ) ;
123+ }
122124 }
123125 }
126+ catch ( Exception _ ) when ( _ is PipelineStoppedException or FlowControlException )
127+ {
128+ throw ;
129+ }
130+ catch ( IdentityNotMappedException exception )
131+ {
132+ exception . WriteIdentityNotFoundError ( this ) ;
133+ }
134+ catch ( Exception exception )
135+ {
136+ exception . WriteUnderterminedError ( this ) ;
137+ }
124138 }
125139
126140 private string ? TryGetIdentityPath ( string ? identity ) => identity switch
0 commit comments