Get-Secret

按名称查找并返回已注册保管库中的机密。

语法

NameParameterSet (默认值)

Get-Secret
    [-Name] <String>
    [[-Vault] <String>]
    [-AsPlainText]
    [<CommonParameters>]

InfoParameterSet

Get-Secret
    [-InputObject] <SecretInformation>
    [-AsPlainText]
    [<CommonParameters>]

说明

此 cmdlet 查找并返回与提供的名称匹配的第一个机密。 如果指定了保管库名称,则仅搜索该保管库。 否则,它会搜索所有保管库并返回第一个匹配结果。 如果保管库注册表具有默认保管库,则 cmdlet 会在任何其他已注册的保管库之前搜索该保管库。 默认情况下,StringSecureString 类型的机密作为 SecureString 对象返回。

示例

示例 1

Get-Secret -Name Secret1 -Vault CredMan
Get-Secret -Name Secret1 -Vault CredMan -AsPlainText
System.Security.SecureString
PlainTextSecretString

此示例搜索名称为 Secret1的机密,该机密是字符串 类型机密。 第一个命令将机密作为 SecureString 对象返回。 第二个命令使用 AsPlainText 参数将机密作为 字符串 对象返回,以纯文本形式显示在控制台中。

示例 2

Get-SecretInfo -Name Secret2 -Vault SecretStore |
    Get-Secret -AsPlainText

此示例检索名为 Secret2的保管库中名为 SecretStore 的机密的机密信息。 然后,它会通过管道将结果发送到 Get-Secret,该管道搜索机密并将其作为纯文本返回。

参数

-AsPlainText

指定类型为 string stringSecureString 的机密应作为 字符串(以纯文本形式)而不是 SecureString返回。 如果要检索的密钥不是 StringSecureString,则此参数无效。

谨慎

为了确保安全性,应尽可能避免使用纯文本字符串。

参数属性

类型:SwitchParameter
默认值:False
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-InputObject

指定表示保管库机密的 SecretInformation 对象,而不是指定 NameVault 参数。 可以使用 cmdlet 获取 Get-SecretInfo 对象。

参数属性

类型:Microsoft.PowerShell.SecretManagement.SecretInformation
默认值:None
支持通配符:False
不显示:False

参数集

InfoParameterSet
Position:0
必需:True
来自管道的值:True
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Name

指定要检索的机密的名称。 不允许使用通配符。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

NameParameterSet
Position:0
必需:True
来自管道的值:True
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Vault

指定要从中检索机密的已注册保管库的名称。 如果未指定保管库名称,则会搜索所有已注册的保管库。 如果 Vault 注册表具有 default vault 且未指定此参数,则在其他已注册的 vault 之前搜索 default vault。

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

NameParameterSet
Position:1
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

CommonParameters

此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters

输入

String

Microsoft.PowerShell.SecretManagement.SecretInformation

输出

Object