@@ -106,33 +106,31 @@ protected override void BeginProcessing()
106106 // retrieve all possible paths
107107 _pathsToSearch = Utils . GetAllResourcePaths ( this ) ;
108108 }
109-
110- if ( Name == null )
111- {
112- Name = new string [ ] { "*" } ;
113- }
114- // if '*' is passed in as an argument for -Name with other -Name arguments,
115- // ignore all arguments except for '*' since it is the most inclusive
116- // eg: -Name ["TestModule, Test*, *"] will become -Name ["*"]
117- if ( Name != null && Name . Length > 1 )
118- {
119- foreach ( var pkgName in Name )
120- {
121- if ( pkgName . Trim ( ) . Equals ( "*" ) )
122- {
123- Name = new string [ ] { "*" } ;
124- break ;
125- }
126- }
127- }
128109 }
129110
130111 protected override void ProcessRecord ( )
131112 {
132113 WriteDebug ( "Entering GetInstalledPSResource" ) ;
133114
115+ var namesToSearch = Utils . ProcessNameWildcards ( Name , out string [ ] errorMsgs , out bool _ ) ;
116+ foreach ( string error in errorMsgs )
117+ {
118+ WriteError ( new ErrorRecord (
119+ new PSInvalidOperationException ( error ) ,
120+ "ErrorFilteringNamesForUnsupportedWildcards" ,
121+ ErrorCategory . InvalidArgument ,
122+ this ) ) ;
123+ }
124+
125+ // this catches the case where Name wasn't passed in as null or empty,
126+ // but after filtering out unsupported wildcard names in BeginProcessing() there are no elements left in Name
127+ if ( namesToSearch . Length == 0 )
128+ {
129+ return ;
130+ }
131+
134132 GetHelper getHelper = new GetHelper ( this ) ;
135- foreach ( PSResourceInfo pkg in getHelper . FilterPkgPaths ( Name , _versionRange , _pathsToSearch ) )
133+ foreach ( PSResourceInfo pkg in getHelper . FilterPkgPaths ( namesToSearch , _versionRange , _pathsToSearch ) )
136134 {
137135 WriteObject ( pkg ) ;
138136 }
0 commit comments