我一直在尝试围绕创建和刷新AD服务主体和应用程序进行大量操作。我遇到麻烦的流程是:
PS> Get-AzureKeyVaultCertificate -VaultName证书-Name CertName
姓名:证书名称
证书:[主题]
CN = certName.foo.com
[发行人]
CN = certName.foo.com
[序列号]
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[不早于]
2017/6/2下午5:41:26
[不之后]
2018/6/2下午5:51:26
[缩略图]
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ID:https://certs.vault.azure.net:443/certificates/certname/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
KeyId:https://certs.vault.azure.net:443/keys/certname/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SecretId:https://certs.vault.azure.net:443/secrets/certname/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
指纹:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
标记:{[缩略图,XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX]}
已启用:True
创建时间:6/3/2017 2:11:31 AM
更新日期:2017/6/3 2:11:31
PS> New-AzureRmADServicePrincipal -DisplayName“证书访问权” -CertValue $([[System.Convert]::ToBase64String($ cert.Certificate.GetRawCertData()))-StartDate $ cert.Certificate.GetEffectiveDateString()-EndDate $ cert.Certificate .GetExpirationDateString()
New-AzureRmADServicePrincipal: key 证书的开始日期无效。
在第1行:char:1
+ New-AzureRmADServicePrincipal -DisplayName“证书访问权”-...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo:InvalidOperation :( :) [New-AzureRmADServicePrincipal],异常
+ FullyQualifiedErrorId:Request_BadRequest,Microsoft.Azure.Commands.ActiveDirectory.NewAzureADServicePrincipalCommand
为什么我得到 key 凭证开始日期无效?
最佳答案
根据您的错误日志,似乎时间格式有误。我建议您可以使用[System.DateTime]::Now
设置时间。我在实验室中进行了测试,但不符合您的错误记录,以下脚本适用于我。我建议你可以测试。
##import certificate to key valut
$Password = ConvertTo-SecureString -String "*******" -AsPlainText -Force
Import-AzureKeyVaultCertificate -VaultName "shuikey" -Name "ImportCert01" -FilePath "C:\shui.pfx" -Password $Password
##set start time and expire time
$now = [System.DateTime]::Now
$yearfromnow = $now.AddYears(1)
##Get certificate from key vault
$cert=Get-AzureKeyVaultCertificate -VaultName certs -Name CertName
New-AzureRmADServicePrincipal -DisplayName "Cert access" -CertValue $([System.Convert]::ToBase64String($cert.Certificate.GetRawCertData())) -StartDate $now -EndDate $yearfromnow
关于powershell - 为什么我在尝试创建Active Directory服务主体时得到 "Key credential start date is invalid.",我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44792762/