Find-RoleCapability
在模块中查找角色功能。
语法
Find-RoleCapability
[[-Name] <String[]>]
[-ModuleName <String>]
[-MinimumVersion <String>]
[-MaximumVersion <String>]
[-RequiredVersion <String>]
[-AllVersions]
[-AllowPrerelease]
[-Tag <String[]>]
[-Filter <String>]
[-Proxy <Uri>]
[-ProxyCredential <PSCredential>]
[-Repository <String[]>]
[<CommonParameters>]
说明
该 Find-RoleCapability
cmdlet 搜索已注册的存储库以查找 PowerShell 角色功能和模块。
对于找到 Find-RoleCapability
的每个角色功能,将返回 PSGetRoleCapabilityInfo 对象。
可以将 PSGetRoleCapabilityInfo 对象向下 Install-Module
发送到或 Save-Module
cmdlet。
PowerShell 角色功能定义在 Just Enough Administration (JEA) 终结点的用户可以使用哪些命令和应用程序。 角色功能由扩展名 .psrc
为的文件定义。
示例
示例 1:查找角色功能
Find-RoleCapability
在每个已注册的存储库中查找角色功能。 若要搜索特定存储库,请使用 Repository 参数。
Find-RoleCapability
Name Version ModuleName Repository
---- ------- ---------- ----------
General-Lev1 1.0 JeaExamples PSGallery
General-Lev2 1.0 JeaExamples PSGallery
IIS-Lev1 1.0 JeaExamples PSGallery
IIS-Lev2 1.0 JeaExamples PSGallery
示例 2:按名称查找角色功能
Find-RoleCapability
按名称查找角色功能。 使用逗号分隔名称数组。
Find-RoleCapability -Name General-Lev1, IIS-Lev2
Name Version ModuleName Repository
---- ------- ---------- ----------
General-Lev1 1.0 JeaExamples PSGallery
IIS-Lev2 1.0 JeaExamples PSGallery
示例 3:查找和保存角色功能的模块
该 Find-RoleCapability
cmdlet 查找角色功能,并将对象发送到管道。
Save-Module
将角色功能的模块保存到文件系统。
Get-ChildItem
显示模块目录的内容。
PS> Find-RoleCapability -Name General-Lev1 | Save-Module -Path C:\Test\Modules
PS> Get-ChildItem -Path C:\Test\Modules\JeaExamples\1.0\
Directory: C:\Test\Modules\JeaExamples\1.0
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 6/4/2019 16:37 RoleCapabilities
-a---- 2/5/2019 18:46 1702 CreateRegisterPSSC.ps1
-a---- 2/5/2019 18:46 7656 JeaExamples.psd1
-a---- 10/1/2018 08:16 595 JeaExamples.psm1
Find-RoleCapability
使用 Name 参数指定 General-Lev1 角色功能。
对象会向下发送管道。
Save-Module
使用文件系统位置 的 Path 参数保存模块。 保存模块后, Get-ChildItem
指定模块 的路径 ,并显示 JeaExamples 模块目录的内容。
示例 4:查找并安装角色功能的模块
Find-RoleCapability
查找模块并将对象发送到管道。
Install-Module
安装模块。 安装后,用于 Get-InstalledModule
查看结果。
Find-RoleCapability -Name General-Lev1 | Install-Module -Verbose
VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/JeaExamples/1.0.0'.
VERBOSE: Completed downloading 'https://www.powershellgallery.com/api/v2/package/JeaExamples/1.0.0'.
VERBOSE: Completed downloading 'JeaExamples'.
VERBOSE: InstallPackageLocal' - name='JeaExamples', version='1.0',
VERBOSE: Validating the 'JeaExamples' module contents
VERBOSE: Test-ModuleManifest successfully validated the module manifest file
VERBOSE: Module 'JeaExamples' was installed successfully to path
Get-InstalledModule
Find-RoleCapability
使用 Name 参数指定 General-Lev1 角色功能。
对象会向下发送管道。
Install-Module
使用 Verbose 参数在安装过程中显示状态消息。 安装完成后, Get-InstalledModule
输出将确认已安装 JeaExamples 模块。
参数
-AllowPrerelease
在结果中包含标记为预发行版的资源。
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-AllVersions
指示此 cmdlet 获取模块的所有版本。 AllVersions 参数显示每个模块的可用版本。
类型: | SwitchParameter |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Filter
根据 PackageManagement 提供程序的搜索语法查找资源。 例如,指定要在 ModuleName 和 Description 属性中搜索的字词。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-MaximumVersion
指定要包含在结果中的模块的最大版本。 MaximumVersion 和 RequiredVersion 参数不能在同一命令中使用。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-MinimumVersion
指定要包含在结果中的模块的最低版本。 MinimumVersion 和 RequiredVersion 参数不能在同一命令中使用。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-ModuleName
指定要在其中搜索角色功能的模块的名称。 默认值为所有模块。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Name
指定角色功能的名称。 默认值为所有角色功能。 使用逗号分隔资源名称数组。
类型: | String[] |
Position: | 0 |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Proxy
为请求指定代理服务器,而不是直接连接到 Internet 资源。
类型: | Uri |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-ProxyCredential
指定有权使用 Proxy 参数中指定的代理服务器的用户帐户。
类型: | PSCredential |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-Repository
指定要搜索角色功能的存储库。 使用逗号分隔存储库名称数组。
类型: | String[] |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-RequiredVersion
指定要包含在结果中的模块的确切版本号。 RequiredVersion 和 MinimumVersion 参数不能在同一命令中使用。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-Tag
指定对存储库中的模块进行分类的标记。 使用逗号分隔标记数组。
类型: | String[] |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
输入
输出
PSGetRoleCapabilityInfo
该 Find-RoleCapability
cmdlet 返回 PSGetRoleCapabilityInfo 对象。
备注
重要
截至 2020 年 4 月,PowerShell 库不再支持传输层安全性(TLS)版本 1.0 和 1.1。 如果未使用 TLS 1.2 或更高版本,则尝试访问 PowerShell 库时会收到错误。 使用以下命令确保使用的是 TLS 1.2:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
有关详细信息,请参阅 PowerShell 博客中的 公告。