我正在使用以下命令获取安装了 Active Directory 证书服务 (ADCS) 的 Windows Server 计算机中已颁发证书的列表。
certutil -restrict 'Disposition=20' -out 'Binary Certificate' -view
一切运行正常,我得到了一个 X509 字符串列表。现在,我想要相同的结果,但需要某种分页,这样每次调用此命令时我都可以得到特定数量的已颁发证书。
我没有找到任何东西certuitl 的手册页,但我可以使用其他工具来完成它,即使需要一些 Powershell 实用程序。
只是为了澄清一下,我通过一个调用它的脚本来使用此命令温控器连接,所以我需要以编程方式解决它。
目前,当我使用该命令时,我会得到一个包含所有已颁发证书的长字符串。例如,如果我有 3 个已颁发的证书,则此命令的输出将是:
Row 1:
Binary Certificate:
-----BEGIN CERTIFICATE-----
MIIEyDCCA7CgAwIBAgIRALL+P2asRHyfAgAAAAB9mgMwDQYJKoZIhvcNAQELBQAw
QjELMAkGA1UEBhMCVVMxHjAcBgNVBAoTFUdvb2dsZSBUcnVzdCBTZXJ2aWNlczET
MBEGA1UEAxMKR1RTIENBIDFPMTAeFw0yMDEwMDYwNjQxMjBaFw0yMDEyMjkwNjQx
MjBaMGgxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQH
Ew1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKEwpHb29nbGUgTExDMRcwFQYDVQQDEw53
d3cuZ29vZ2xlLmNvbTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABGp8Sp01kEsr
Gz98cyb/Kt+xvLJzsqGgIAOXjdHfjOzOUJTiMJIB/NIpQnDvNZ9L3qF3Zl2ecyFY
ZoI5LMyTrImjggJcMIICWDAOBgNVHQ8BAf8EBAMCB4AwEwYDVR0lBAwwCgYIKwYB
BQUHAwEwDAYDVR0TAQH/BAIwADAdBgNVHQ4EFgQUXXztHYUOkjN796BgKuPdcGaL
iVswHwYDVR0jBBgwFoAUmNH4bhDrz5vsYJ8YkBug630J/SswaAYIKwYBBQUHAQEE
XDBaMCsGCCsGAQUFBzABhh9odHRwOi8vb2N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KX7/OeNddrwoVZnRmwvUddbx2rqU8TZdvJMAQaecot8bty
TVPk+4gxuNxIZSLufY7uDh/qZYNSc2/pSfyyM8CKO54Uq8VqVVb5tGmSXLWRbtBY
pM8zLEwTp1yoOFB3P5GCrZX63/USA8COaE32Ow==
-----END CERTIFICATE-----
对于这个例子,我重复了3次相同的证书,但真正的结果将带来3个不同的证书
我想要的是类似的东西certutil -restrict 'Disposition=20' -out 'Binary Certificate' -view -page 1 -pagesize 2
:(该命令不存在) 将带来完全相同的信息,但只需 2 个证书,然后使用相同的命令-page 2
将带来最后一个。
是否可以?
信息:
- Windows Server 2016(理想的解决方案也适用于旧版本)
- Powershell 5.1
答案1
最简单的方法是使用管道Out-Host -Paging
。这样您就可以使用空格键一次前进一页。
certutil -restrict 'Disposition=20' -out 'Binary Certificate' -view | Out-Host -Paging
您还可以计算此命令的结果:
$f = certutil -restrict 'Disposition=20' -out 'Binary Certificate' -view | Select-Object Name | Measure
$f.Count