@@ -184,21 +184,16 @@ public IEnumerable<PSResourceInfo> FindByResourceName(
184184
185185 List < string > repositoryNamesToSearch = new List < string > ( ) ;
186186
187- Uri [ ] allowedRepostories = null ;
188-
189- if ( GroupPolicyRepositoryEnforcement . IsGroupPolicyEnabled ( ) )
190- {
191- allowedRepostories = GroupPolicyRepositoryEnforcement . GetAllowedRepositoryURIs ( ) ;
192- }
193-
194187 for ( int i = 0 ; i < repositoriesToSearch . Count ; i ++ )
195188 {
196189 PSRepositoryInfo currentRepository = repositoriesToSearch [ i ] ;
197190
198- if ( allowedRepostories != null && ! allowedRepostories . Contains ( currentRepository . Uri ) )
191+ bool isAllowed = GroupPolicyRepositoryEnforcement . IsRepositoryAllowed ( currentRepository . Uri ) ;
192+
193+ if ( ! isAllowed )
199194 {
200195 _cmdletPassedIn . WriteError ( new ErrorRecord (
201- new PSInvalidOperationException ( $ "Repository '{ currentRepository . Name } ' is not allowed by group policy .") ,
196+ new PSInvalidOperationException ( $ "Repository '{ currentRepository . Name } ' is not allowed by Group Policy .") ,
202197 "RepositoryNotAllowedByGroupPolicy" ,
203198 ErrorCategory . PermissionDenied ,
204199 this ) ) ;
@@ -376,6 +371,20 @@ public IEnumerable<PSCommandResourceInfo> FindByCommandOrDscResource(
376371 for ( int i = 0 ; i < repositoriesToSearch . Count ; i ++ )
377372 {
378373 PSRepositoryInfo currentRepository = repositoriesToSearch [ i ] ;
374+
375+ bool isAllowed = GroupPolicyRepositoryEnforcement . IsRepositoryAllowed ( currentRepository . Uri ) ;
376+
377+ if ( ! isAllowed )
378+ {
379+ _cmdletPassedIn . WriteError ( new ErrorRecord (
380+ new PSInvalidOperationException ( $ "Repository '{ currentRepository . Name } ' is not allowed by Group Policy.") ,
381+ "RepositoryNotAllowedByGroupPolicy" ,
382+ ErrorCategory . PermissionDenied ,
383+ this ) ) ;
384+
385+ continue ;
386+ }
387+
379388 repositoryNamesToSearch . Add ( currentRepository . Name ) ;
380389 _networkCredential = Utils . SetNetworkCredential ( currentRepository , _networkCredential , _cmdletPassedIn ) ;
381390 ServerApiCall currentServer = ServerFactory . GetServer ( currentRepository , _cmdletPassedIn , _networkCredential ) ;
@@ -566,6 +575,20 @@ public IEnumerable<PSResourceInfo> FindByTag(
566575 for ( int i = 0 ; i < repositoriesToSearch . Count ; i ++ )
567576 {
568577 PSRepositoryInfo currentRepository = repositoriesToSearch [ i ] ;
578+
579+ bool isAllowed = GroupPolicyRepositoryEnforcement . IsRepositoryAllowed ( currentRepository . Uri ) ;
580+
581+ if ( ! isAllowed )
582+ {
583+ _cmdletPassedIn . WriteError ( new ErrorRecord (
584+ new PSInvalidOperationException ( $ "Repository '{ currentRepository . Name } ' is not allowed by Group Policy.") ,
585+ "RepositoryNotAllowedByGroupPolicy" ,
586+ ErrorCategory . PermissionDenied ,
587+ this ) ) ;
588+
589+ continue ;
590+ }
591+
569592 repositoryNamesToSearch . Add ( currentRepository . Name ) ;
570593 _networkCredential = Utils . SetNetworkCredential ( currentRepository , _networkCredential , _cmdletPassedIn ) ;
571594 ServerApiCall currentServer = ServerFactory . GetServer ( currentRepository , _cmdletPassedIn , _networkCredential ) ;
0 commit comments