以下内容根本不起作用:
Remove-DnsServerSigningKey -KeyId $key.KeyId -ZoneName $zonename -Force
其中 $zonename 是有效区域,并且 key-id 存在且有效。如果我首先取消签名区域,则此命令有效,但我想在辞职后执行此操作。
逻辑:
- 获取所有当前区域签名密钥
- 添加一个新的 ZSK
- 使用新的 ZSK 退出区域
- 休眠 3 秒(仅用于宽限期)
- 循环遍历所有以前的键(此时,新键不在列表中)
- 删除前一个键
当尝试删除以前的键时,我得到:
Remove-DnsServerSigningKey : Failed to delete the signing key __[Key-ID]__ for the zone __[Key-ID]__ on server __[Server-addr]__ Please check
extended error for additional details.
At C:\Users\Administrator\Desktop\dnssec.ps1:79 char:13
+ Remove-DnsServerSigningKey -KeyId $key.KeyId -ZoneName $zonename -Fo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (__[Key-Id]__:root/Microsoft/...erverSigningKey) [Remove-DnsServerSigningKey], CimException
+ FullyQualifiedErrorId : WIN32 9119,Remove-DnsServerSigningKey
代码如下所示:
function resign {
param(
[string]$zonename
)
$zonename + " <- Re-Signing"
## Grab all current keys (incl active ones)
$keys = Get-DnsServerSigningKey -ZoneName $zonename
$zonename + " <- Creating new ZSK"
#Add a new ZSK
Add-DnsServerSigningKey -ZoneName $zonename -ComputerName 127.0.0.1 -CryptoAlgorithm RsaSha256 -Type ZoneSigningKey
#Resign the zone with the newly added key
Invoke-DnsServerZonesign -ZoneName $zonename –DoResign -Force
Start-Sleep -s 1
# After the resign, we delete all previous ZONE signing keys (but keep KSK)
$zonename + " <- Removing ZSKeys"
foreach ($key in $keys) {
if ($key.KeyType -eq "ZoneSigningKey") {
Remove-DnsServerSigningKey -ComputerName 127.0.0.1 -ZoneName $zonename -KeyId $key.KeyId -Force
}
}
}
Notabel 可能是,如果我完全取消对该区域的签名并运行相同的删除键代码,它就可以工作。只是在退出一个区域时它不起作用。我要删除的密钥是 ZoneSigningKey 类型,而不是 KeySigningKey(已验证)。