Powershell脚本,用于扫描OU中所有未工作的服务器的过期SSL证书
我已使用域\管理员帐户作为凭据来运行以下PowerShell脚本以扫描过期的SSL证书:Powershell脚本,用于扫描OU中所有未工作的服务器的过期SSL证书,powershell,scripting,active-directory,windows-scripting,Powershell,Scripting,Active Directory,Windows Scripting,我已使用域\管理员帐户作为凭据来运行以下PowerShell脚本以扫描过期的SSL证书: $ScriptBlock = { Get-ChildItem Cert:\*\My -Recurse | Select-Object Subject, DnsNameList, NotAfter, NotBefore, Thumbprint, Issuer, @{n = "SAN
$ScriptBlock = {
Get-ChildItem Cert:\*\My -Recurse |
Select-Object Subject,
DnsNameList,
NotAfter,
NotBefore,
Thumbprint,
Issuer,
@{n = "SAN"; e = {Try {($_.Extensions | Where-Object {$_.Oid.Value -eq '2.5.29.17'}).Format(0)} Catch {} }},
@{n = "IsValid"; e = {$today = Get-Date; If ( $_.NotBefore -lt $today -and $_.NotAfter -gt $today ) { $true } Else {$false} } } }
$computers = Get-ADComputer -Filter {Enabled -eq $True -and OperatingSystem -like "*Server*"} -SearchBase "OU=Servers,OU=Production Site 1,DC=Domain,DC=com" |
Where-Object {Test-Connection $_.Name -Count 1 -Quiet} |
Select-Object -expandProperty DnsHostName |
Export-Csv -Path C:\Logs\SSL.csv -NoTypeInformation
$adCred = Get-Credential Invoke-Command -ComputerName $computers
-ScriptBlock $ScriptBlock -Credential $adCred
但是,后来我发现了一个错误:
[Microsoft.PowerShell.Commands.Internal.Format.FormatteryData]
连接到远程服务器
Microsoft.PowerShell.Commands.Internal.Format.FormatteryData失败
出现以下错误消息:WinRM无法处理该请求。
使用Kerberos身份验证时发生以下错误:
找不到计算机
Microsoft.PowerShell.Commands.Internal.Format.FormatteryData。验证
计算机是否存在于网络上,并且提供的名称是否正确
拼写正确。有关更多信息,请参阅
关于远程故障排除帮助主题。
+CategoryInfo:OpenError:(Microsoft.Power…FormatEntryData:String)[],PSRemotingTransportException
+FullyQualifiedErrorId:NetworkPathNotFound,PSSessionStateBreaked
如何修复它以获得CSV结果
更新后的错误代码现在为:
Invoke命令:无法验证参数“ComputerName”上的参数。
参数为null或为空。提供一个非空或非空的参数
为空,然后重试该命令。第19行字符:30
+调用命令-ComputerName$computers-ScriptBlock$ScriptBlock-Cr。。。
+ ~~~~~~~~~~
+CategoryInfo:InvalidData:(:)[Invoke Command],ParameterBindingValidationException
+FullyQualifiedErrorId:ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
该行不适合启动
$computers = Get-ADComputer -Filter {Enabled -eq $True} -SearchBase "OU=Servers,OU=Production,DC=Domain,DC=com" |
Select-Object -expandProperty DnsHostName |
Select-Object -expandProperty DnsHostName | #bad line
Export-Csv -Path C:\Logs\SSL.csv -NoTypeInformation
应该是
$computers = Get-ADComputer -Filter {Enabled -eq $True} -SearchBase "OU=Servers,OU=Production,DC=Domain,DC=com" |
Select-Object -expandProperty DnsHostName |
Export-Csv -Path C:\Logs\SSL.csv -NoTypeInformation
该行不适合启动
$computers = Get-ADComputer -Filter {Enabled -eq $True} -SearchBase "OU=Servers,OU=Production,DC=Domain,DC=com" |
Select-Object -expandProperty DnsHostName |
Select-Object -expandProperty DnsHostName | #bad line
Export-Csv -Path C:\Logs\SSL.csv -NoTypeInformation
应该是
$computers = Get-ADComputer -Filter {Enabled -eq $True} -SearchBase "OU=Servers,OU=Production,DC=Domain,DC=com" |
Select-Object -expandProperty DnsHostName |
Export-Csv -Path C:\Logs\SSL.csv -NoTypeInformation
找不到计算机
=看起来您正试图连接到一台不存在、脱机或无法访问的计算机。您的代码建议您将$erroractionpreference设置为“静默”或“忽略”,这对于开发代码来说是可怕的。这里重复的expand语句将出错:$computers=Get-ADComputer-Filter{Enabled-eq$True}-SearchBase“OU=Servers,OU=Production,DC=Domain,DC=com”|选择Object-expandProperty DnsHostName |选择Object-expandProperty DnsHostName |导出Csv-Path C:\Logs\SSL.Csv-notypeInformations作为旁白:最好是这样。我已经用格式更新了代码,它现在正在抱怨相同的错误。注意,我们更喜欢这里的技术写作风格。我们轻轻地劝阻问候,希望你能帮助,谢谢,提前感谢,感谢信,问候,亲切的问候,签名,请你能帮助,闲聊的材料和缩写的txtspk,恳求,你被困多久了,投票建议,元评论等。只需解释你的问题,并展示你已经尝试了什么,你期望什么,以及实际发生的情况。找不到计算机
=看起来您正试图连接到一台不存在、脱机或无法访问的计算机。您的代码建议您将$erroractionpreference设置为“静默”或“忽略”,这对于开发代码来说非常糟糕。这里重复的expand语句将出错:$computers=Get-ADComputer-Filter{Enabled-eq$True}-SearchBase“OU=Servers,OU=Production,DC=Domain,DC=com”|选择Object-expandProperty DnsHostName |选择Object-expandProperty DnsHostName |导出Csv-Path C:\Logs\SSL.Csv-notypeInformations作为旁白:最好是这样。我已经用格式更新了代码,它现在正在抱怨相同的错误。注意,我们更喜欢这里的技术写作风格。我们轻轻地劝阻问候,希望你能帮助,谢谢,提前感谢,感谢信,问候,亲切的问候,签名,请你能帮助,闲聊的材料和缩写的txtspk,恳求,你被困多久了,投票建议,元评论等。只需解释你的问题,并展示你已经尝试了什么,你期望什么,详细说明:管道段Select Object-expandProperty DnsHostName
在原始命令中意外重复,您删除了重复项(这将有助于添加该描述,并将命令分散到多行)。顺便说一句:最好。详细说明:管道段选择对象-expandProperty DnsHostName
在原始命令中意外重复,您删除了重复项(这将有助于添加该描述,并将命令分散到多行)。顺便说一句:最好是。