|
| 1 | +# Replaces: Find-Command, Find-DscResource, Find-Module, Find-RoleCapability, Find-Script |
| 2 | +# Parameter Sets: ResourceParameterSet, PackageParameterSet, ScriptParameterSet |
| 3 | + |
| 4 | +# Find-Command returns an object with properties: Name, Version, ModuleName, Repository |
| 5 | +# Find-DSCResource returns an object with properties: Name, Version, ModuleName, Repository |
| 6 | +# Find-RoleCapability returns an object with properties: Name, Version, ModuleName, Repository |
| 7 | + |
| 8 | +# Find-Module returns an object with properties: Version, Name, Repository, Description |
| 9 | +# Find-Script returns an object with properties: Version, Name, Repository, Description |
| 10 | + |
| 11 | +function Find-PSResource { |
| 12 | + [OutputType([PSCustomObject[]])] |
| 13 | + [Cmdletbinding(SupportsShouldProcess = $true)] |
| 14 | + Param |
| 15 | + ( |
| 16 | + # Specifies the name of the resource to be searched for. |
| 17 | + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. |
| 18 | + [Parameter(ValueFromPipeline = $true, |
| 19 | + ValueFromPipelineByPropertyName = $true, |
| 20 | + Position = 0)] |
| 21 | + [ValidateNotNullOrEmpty()] |
| 22 | + [string[]] |
| 23 | + $Name, |
| 24 | + |
| 25 | + # Specifies the type of the resource being searched. |
| 26 | + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. |
| 27 | + [Parameter(ValueFromPipelineByPropertyName = $true)] |
| 28 | + [ValidateSet('Module', 'Script', 'DscResource', 'RoleCapability', 'Command')] |
| 29 | + [string[]] |
| 30 | + $Type, |
| 31 | + |
| 32 | + # Specifies the module name that contains the resource. |
| 33 | + # Resources that use this param: Command, DSCResource, RoleCapability. |
| 34 | + [Parameter(ParameterSetName = "ResourceParameterSet")] |
| 35 | + [ValidateNotNullOrEmpty()] |
| 36 | + [string] |
| 37 | + $ModuleName, |
| 38 | + |
| 39 | + # Specifies the minimum version of the resource to include in results (cannot use this parameter with the RequiredVersion or AllVersions parameters). |
| 40 | + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. |
| 41 | + [Parameter(ValueFromPipelineByPropertyName = $true)] |
| 42 | + [ValidateNotNull()] |
| 43 | + [string] |
| 44 | + $MinimumVersion, |
| 45 | + |
| 46 | + # Specifies the maximum version of the resource to include in results (cannot use this parameter with the RequiredVersion or AllVersions parameters). |
| 47 | + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. |
| 48 | + [Parameter(ValueFromPipelineByPropertyName = $true)] |
| 49 | + [ValidateNotNull()] |
| 50 | + [string] |
| 51 | + $MaximumVersion, |
| 52 | + |
| 53 | + # Specifies the required version of the resource to include in results (cannot use this parameter with the MinimumVersion, MaximumVersion, or AllVersions parameters). |
| 54 | + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. |
| 55 | + [Parameter(ValueFromPipelineByPropertyName = $true)] |
| 56 | + [ValidateNotNull()] |
| 57 | + [string] |
| 58 | + $RequiredVersion, |
| 59 | + |
| 60 | + # Displays each of a resource's available versions (cannot use this parameter with the MinimumVersion, MaximumVersion, or RequiredVersion parameters). |
| 61 | + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. |
| 62 | + [Parameter()] |
| 63 | + [switch] |
| 64 | + $AllVersions, |
| 65 | + |
| 66 | + # Includes resources marked as a prerelease. |
| 67 | + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. |
| 68 | + [Parameter()] |
| 69 | + [switch] |
| 70 | + $Prerelease, |
| 71 | + |
| 72 | + # Specifies tags that categorize modules in a repository. |
| 73 | + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. |
| 74 | + [Parameter()] |
| 75 | + [ValidateNotNull()] |
| 76 | + [string[]] |
| 77 | + $Tag, |
| 78 | + |
| 79 | + # Finds resources based on ModuleName, Description, and Tag properties. |
| 80 | + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. |
| 81 | + [Parameter()] |
| 82 | + [ValidateNotNull()] |
| 83 | + [string] |
| 84 | + $Filter, |
| 85 | + |
| 86 | + # Specifies a proxy server for the request, rather than a direct connection to the internet resource. |
| 87 | + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. |
| 88 | + [Parameter(ValueFromPipelineByPropertyName = $true)] |
| 89 | + [ValidateNotNullOrEmpty()] |
| 90 | + [Uri] |
| 91 | + $Proxy, |
| 92 | + |
| 93 | + # Specifies a user account that has permission to use the proxy server that is specified by the Proxy parameter. |
| 94 | + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. |
| 95 | + [Parameter(ValueFromPipelineByPropertyName = $true)] |
| 96 | + [PSCredential] |
| 97 | + $ProxyCredential, |
| 98 | + |
| 99 | + # Specifies the repository to search within (default is all repositories). |
| 100 | + # Resources that use this param: Command, DSCResource, RoleCapability, Package, Script. |
| 101 | + [Parameter()] |
| 102 | + [ValidateNotNullOrEmpty()] |
| 103 | + [string[]] |
| 104 | + $Repository, |
| 105 | + |
| 106 | + # Specifies a user account that has rights to find a resource from a specific repository. |
| 107 | + # Resources that use this param: Package, Script. |
| 108 | + [Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = "PackageParameterSet")] |
| 109 | + [Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = "ScriptParameterSet")] |
| 110 | + [PSCredential] |
| 111 | + $Credential, |
| 112 | + |
| 113 | + # Specifies to include all modules that are dependent upon the module specified in the Name parameter. |
| 114 | + # Resources that use this param: Package, Script. |
| 115 | + [Parameter(ParameterSetName = "PackageParameterSet")] |
| 116 | + [Parameter(ParameterSetName = "ScriptParameterSet")] |
| 117 | + [switch] |
| 118 | + $IncludeDependencies, |
| 119 | + |
| 120 | + # Returns only those modules that include specific kinds of PowerShell functionality. For example, you might only want to find modules that include DSCResource. |
| 121 | + # The acceptable values for this parameter are as follows: |
| 122 | + # Module: DscResource, Cmdlet, Function, RoleCapability; |
| 123 | + # Scripts: Function, Workflow; |
| 124 | + # Resources that use this param: Package, Script. |
| 125 | + [Parameter(ParameterSetName = "PackageParameterSet")] |
| 126 | + [Parameter(ParameterSetName = "ScriptParameterSet")] |
| 127 | + [ValidateNotNull()] |
| 128 | + [ValidateSet('DscResource', 'Cmdlet', 'Function', 'RoleCapability', 'Workflow')] |
| 129 | + [string[]] |
| 130 | + $Includes, |
| 131 | + |
| 132 | + # Specifies the name of the DSC resources contained within a module (per PowerShell conventions, performs an OR search when you provide multiple arguments). |
| 133 | + # Resources that use this param: Package. |
| 134 | + [Parameter(ParameterSetName = "PackageParameterSet")] |
| 135 | + [ValidateNotNull()] |
| 136 | + [string[]] |
| 137 | + $DscResource, |
| 138 | + |
| 139 | + # Specifies the name of the role capabilities contained within a module (per PowerShell conventions, performs an OR search when you provide multiple arguments). |
| 140 | + # Resources that use this param: Package. |
| 141 | + [Parameter(ParameterSetName = "PackageParameterSet")] |
| 142 | + [ValidateNotNull()] |
| 143 | + [string[]] |
| 144 | + $RoleCapability, |
| 145 | + |
| 146 | + # Specifies commands to find in modules (command can be a function or workflow). |
| 147 | + # Resources that use this param: Package, Script. |
| 148 | + [Parameter(ParameterSetName = "PackageParameterSet")] |
| 149 | + [Parameter(ParameterSetName = "ScriptParameterSet")] |
| 150 | + [ValidateNotNull()] |
| 151 | + [string[]] |
| 152 | + $Command |
| 153 | + |
| 154 | + ) |
| 155 | + |
| 156 | + begin { |
| 157 | + # For each repository, if local cache does not exist then Update-PSResourceCache |
| 158 | + } |
| 159 | + process { |
| 160 | + |
| 161 | + # Returning the array of resources |
| 162 | + $foundResources |
| 163 | + |
| 164 | + foreach ($n in $name) { |
| 165 | + |
| 166 | + if ($pscmdlet.ShouldProcess($n)) { |
| 167 | + |
| 168 | + $PSResource = [PSCustomObject] @{ |
| 169 | + Name = $Name |
| 170 | + Version = "placeholder-for-module-version" |
| 171 | + Type = $Type |
| 172 | + Description = "placeholder-for-description" |
| 173 | + } |
| 174 | + |
| 175 | + $foundResources += $PSResource |
| 176 | + } |
| 177 | + } |
| 178 | + |
| 179 | + return $foundResources |
| 180 | + } |
| 181 | + end { } |
| 182 | +} |
0 commit comments