我编写了一个脚本,其中将将所有SSL证书详细信息从我的计算机导出到Excel表,但我需要导出映射到IIS中特定站点的证书,然后需要将这些包含站点名称和证书详细信息的详细信息导出到Excel工作表中。
码
#Clearing the Console host in PS
Clear-Host
#Installing the Excel module to the Powershell
Install-Module -Name ImportExcel
#List of Servers
$computers = Get-Content "C:\TEMP\servers.txt"
#Number of days to look for expiring certificates
$threshold = 300
#Set deadline date
$deadline = (Get-Date).AddDays($threshold)
Invoke-Command -ComputerName $computers {
Get-ChildItem -Path 'Cert:\LocalMachine\My' -Recurse |
Select-Object -Property @{n='ServerName';e={$env:COMPUTERNAME}},Issuer, Subject, NotAfter,
#@{Label = 'ServerName';Expression = {$env:COMPUTERNAME}}
@{Label='Expires In (Days)';Expression = {(New-TimeSpan -Start (Get-Date) -End $PSitem.NotAfter).Days}}
} | Export-Excel -Path C:\users\$env:username\documents\MultipleServer_Certificate_Expiry_Details.xlsx`
发布于 2020-02-06 00:24:49
这是一件非常常见的事情,在这个IIS用例上,web上有很多文章和示例。这就是web管理模块的用途。
<#
Get all IIS bindings and SSL certificates
On a local or remote IIS PowerShell Session
#>
Import-Module -Name WebAdministration
Get-ChildItem -Path IIS:SSLBindings |
ForEach-Object -Process {
if ($_.Sites)
{
$certificate = Get-ChildItem -Path CERT:LocalMachine/My |
Where-Object -Property Thumbprint -EQ -Value $_.Thumbprint
[PsCustomObject]@{
Sites = $_.Sites.Value
CertificateFriendlyName = $certificate.FriendlyName
CertificateDnsNameList = $certificate.DnsNameList
CertificateNotAfter = $certificate.NotAfter
CertificateIssuer = $certificate.Issuer
}
}
}
定制上面的内容以满足您的输出需求。
注意,如果您碰巧使用的是传统版本的PowerShell:
PsCustomObject@{}不会在PS2.0中工作,但您可以用新对象-TypeName PSObject替换它
更新
您已经要求在多个服务器上运行一个示例脚本。然而,您已经在您的帖子中有代码了。只需将调用命令放在ForEach循环中,并传入计算机列表即可。
$Computers |
ForEach {
Invoke-Command -ComputerName $PSItem -ScriptBlock {
Get-ChildItem -Path 'Cert:\LocalMachine\My' -Recurse |
Select-Object -Property @{n='ServerName';e={$env:COMPUTERNAME}},Issuer, Subject, NotAfter,
@{Label='Expires In (Days)';Expression = {(New-TimeSpan -Start (Get-Date) -End $PSitem.NotAfter).Days}}
} | Export-Excel -Path "C:\users\$env:username\documents\MultipleServer_Certificate_Expiry_Details.xlsx"
}
当然,您需要将Web Admin块的示例添加到您的cert数据点中
https://stackoverflow.com/questions/60075064
复制相似问题