New-EntraApplicationKeyCredential
为应用程序创建密钥凭据。
语法
Default (默认值)
New-EntraApplicationKeyCredential
-ApplicationId <String>
[-CustomKeyIdentifier <String>]
[-Type <KeyType>]
[-Usage <KeyUsage>]
[-Value <String>]
[-EndDate <DateTime>]
[-StartDate <DateTime>]
[<CommonParameters>]
说明
该 New-EntraApplicationKeyCredential cmdlet 为应用程序创建密钥凭据。
应用程序可以使用此命令自动 Remove-EntraApplicationKeyCredential 滚动更新其过期密钥。
作为请求验证的一部分,先验证拥有现有密钥的证据,然后才能执行该操作。
示例
示例 1:创建新的应用程序密钥凭据
Connect-Entra -Scopes 'Application.ReadWrite.All','Application.ReadWrite.OwnedBy'
$application = Get-EntraApplication -Filter "DisplayName eq 'Contoso Helpdesk Application'"
$params = @{
ApplicationId = $application.Id
CustomKeyIdentifier = 'EntraPowerShellKey'
StartDate = '2024-03-21T14:14:14Z'
Type = 'Symmetric'
Usage = 'Sign'
Value = '<my-value>'
}
New-EntraApplicationKeyCredential @params
CustomKeyIdentifier : {84, 101, 115, 116}
EndDate : 2024-03-21T14:14:14Z
KeyId : aaaaaaaa-0b0b-1c1c-2d2d-333333333333
StartDate : 2025-03-21T14:14:14Z
Type : Symmetric
Usage : Sign
Value : {49, 50, 51}
此示例演示如何创建应用程序密钥凭据。
-
-ApplicationId指定应用程序的唯一 ID -
-CustomKeyIdentifier指定自定义密钥 ID。 -
-StartDate指定键作为 DateTime 对象生效的时间。 -
-Type指定键的类型。 -
-Usage指定密钥用法。 对于AsymmetricX509Cert用法必须为Verify,并且X509CertAndPassword对于用法必须为Sign。 -
-Value指定键的值。
可以使用 Get-EntraApplication cmdlet 检索应用程序对象 ID。
示例 2:使用证书添加应用程序密钥凭据
Connect-Entra -Scopes 'Application.ReadWrite.All','Application.ReadWrite.OwnedBy'
$application = Get-EntraApplication -Filter "DisplayName eq 'Contoso Helpdesk Application'"
$cer = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 #create a new certificate object
$cer.Import('C:\Users\ContosoUser\appcert.cer')
$bin = $cer.GetRawCertData()
$base64Value = [System.Convert]::ToBase64String($bin)
$bin = $cer.GetCertHash()
$base64Thumbprint = [System.Convert]::ToBase64String($bin)
$keyid = [System.Guid]::NewGuid().ToString()
$params = @{
ApplicationId = $application.Id
CustomKeyIdentifier = $base64Thumbprint
Type = 'AsymmetricX509Cert'
Usage = 'Verify'
Value = $base64Value
StartDate = $cer.GetEffectiveDateString()
EndDate = $cer.GetExpirationDateString()
}
New-EntraApplicationKeyCredential @params
此示例演示如何创建应用程序密钥凭据。
-
-ApplicationId指定应用程序的唯一 ID -
-CustomKeyIdentifier指定自定义密钥 ID。 -
-StartDate指定键作为 DateTime 对象生效的时间。 -
-EndDate指定键作为 DateTime 对象无效的时间。 -
-Type指定键的类型。 -
-Usage指定密钥用法。 对于AsymmetricX509Cert用法必须为Verify,并且X509CertAndPassword对于用法必须为Sign。 -
-Value指定键的值。
参数
-ApplicationId
指定Microsoft Entra ID中应用程序的唯一 ID。
参数属性
| 类型: | System.String |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
| 别名: | 对象标识符 (ObjectId) |
参数集
(All)
| Position: | Named |
| 必需: | True |
| 来自管道的值: | True |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
-CustomKeyIdentifier
指定自定义密钥 ID。
参数属性
| 类型: | System.String |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | True |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
-EndDate
指定键作为 DateTime 对象无效的时间。
参数属性
| 类型: | System.DateTime |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | True |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
-StartDate
指定键作为 DateTime 对象生效的时间。
参数属性
| 类型: | System.DateTime |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | True |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
-Type
指定键的类型。
参数属性
| 类型: | KeyType |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | True |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
-Usage
指定密钥用法。
-
AsymmetricX509Cert:用法必须为Verify。 -
X509CertAndPassword:用法必须为Sign。
参数属性
| 类型: | KeyUsage |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | True |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
-Value
指定键的值。
参数属性
| 类型: | System.String |
| 默认值: | None |
| 支持通配符: | False |
| 不显示: | False |
参数集
(All)
| Position: | Named |
| 必需: | False |
| 来自管道的值: | True |
| 来自管道的值(按属性名称): | True |
| 来自剩余参数的值: | False |
CommonParameters
此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters。