从未过期的新AzureRmADSpCredential密码

Cal*_*ald 5 powershell azure

不确定这是否是我使用它的方式的错误或问题,但基本上我正在尝试使用New-AzureRmADSpCredential向现有Azure服务主体添加非过期密码,但无论我提供给-EndDate参数它从不有效果(总是设定在1年后过期)

示例步骤是:

$start = get-date
$end = $start.AddYears(99)
New-AzureRmADServicePrincipal -DisplayName SPTestnonExpirePW
$sp = Get-AzureRmADServicePrincipal -DisplayName "SPTestnonExpirePW"
New-AzureRmADSpCredential -ObjectId $sp.id -StartDate $start -EndDate $end -Password (ConvertTo-SecureString -String "PASSWORD" -Force -AsPlainText)
Run Code Online (Sandbox Code Playgroud)

无论我为-EndDate提供什么值(只要它是有效的System.DateTime),密码都会成功创建,但是1年到期

我已经在Linux上的PS核心和服务器2016上的PS本机上尝试过这个

Joe*_*Cai 1

经过大量的搜索和测试,我得到了与你相同的结果,根据邮递员的测试,我同意这可能是密码的错误New-AzureRmADSpCredential

另外,如果您想实现凭证永不过期,您可以尝试使用New-AzureRmADAppCredential来实现这一点。

注意ObjectId这里不是你的ServicePrincipalobjectid,而是App注册的objectId,与.app同名ServicePrincipal

$start = get-date
$end = $start.AddYears(150)
$SecureStringPassword = ConvertTo-SecureString -String "password" -AsPlainText -Force
New-AzureRmADAppCredential -ObjectId xxxxxxxxxxxxxxxxxxx -StartDate $start -EndDate $end -Password $SecureStringPassword
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述