@@ -184,21 +184,16 @@ public IEnumerable<PSResourceInfo> FindByResourceName(
184
184
185
185
List < string > repositoryNamesToSearch = new List < string > ( ) ;
186
186
187
- Uri [ ] allowedRepostories = null ;
188
-
189
- if ( GroupPolicyRepositoryEnforcement . IsGroupPolicyEnabled ( ) )
190
- {
191
- allowedRepostories = GroupPolicyRepositoryEnforcement . GetAllowedRepositoryURIs ( ) ;
192
- }
193
-
194
187
for ( int i = 0 ; i < repositoriesToSearch . Count ; i ++ )
195
188
{
196
189
PSRepositoryInfo currentRepository = repositoriesToSearch [ i ] ;
197
190
198
- if ( allowedRepostories != null && ! allowedRepostories . Contains ( currentRepository . Uri ) )
191
+ bool isAllowed = GroupPolicyRepositoryEnforcement . IsRepositoryAllowed ( currentRepository . Uri ) ;
192
+
193
+ if ( ! isAllowed )
199
194
{
200
195
_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 .") ,
202
197
"RepositoryNotAllowedByGroupPolicy" ,
203
198
ErrorCategory . PermissionDenied ,
204
199
this ) ) ;
@@ -376,6 +371,20 @@ public IEnumerable<PSCommandResourceInfo> FindByCommandOrDscResource(
376
371
for ( int i = 0 ; i < repositoriesToSearch . Count ; i ++ )
377
372
{
378
373
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
+
379
388
repositoryNamesToSearch . Add ( currentRepository . Name ) ;
380
389
_networkCredential = Utils . SetNetworkCredential ( currentRepository , _networkCredential , _cmdletPassedIn ) ;
381
390
ServerApiCall currentServer = ServerFactory . GetServer ( currentRepository , _cmdletPassedIn , _networkCredential ) ;
@@ -566,6 +575,20 @@ public IEnumerable<PSResourceInfo> FindByTag(
566
575
for ( int i = 0 ; i < repositoriesToSearch . Count ; i ++ )
567
576
{
568
577
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
+
569
592
repositoryNamesToSearch . Add ( currentRepository . Name ) ;
570
593
_networkCredential = Utils . SetNetworkCredential ( currentRepository , _networkCredential , _cmdletPassedIn ) ;
571
594
ServerApiCall currentServer = ServerFactory . GetServer ( currentRepository , _cmdletPassedIn , _networkCredential ) ;
0 commit comments