【发布时间】:2019-04-24 01:55:17
【问题描述】:
我已使用 DOMAIN\Administrator 帐户作为凭据来运行以下 PowerShell 脚本以扫描过期的 SSL 证书:
$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.FormatEntryData] 连接到远程服务器 Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData 失败 带有以下错误消息:WinRM 无法处理该请求。 使用 Kerberos 身份验证时发生以下错误: 找不到电脑 Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData。核实 该计算机存在于网络上并且提供的名称是 拼写正确。有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。 + CategoryInfo : OpenError: (Microsoft.Power...FormatEntryData:String) [], PSRemotingTransportException + FullyQualifiedErrorId : NetworkPathNotFound,PSSessionStateBroken
如何修复它以便我可以得到 CSV 结果?
现在更新的错误码是:
Invoke-Command:无法验证参数“ComputerName”上的参数。 参数为 null 或空。提供一个不为空的参数或 为空,然后重试该命令。在线:19 字符:30 + 调用命令 -ComputerName $computers -ScriptBlock $ScriptBlock -Cr ... + ~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
【问题讨论】:
-
Cannot find the computer= 看起来您正在尝试连接到不存在、离线或无法访问的计算机 -
您的代码建议您将 $erroractionpreference 设置为静默或忽略,这对于开发代码来说很糟糕。您在此处重复展开语句会出错: $computers = Get-ADComputer -Filter {Enabled -eq $True} -SearchBase "OU=Servers,OU=Production,DC=Domain,DC=com" |选择对象-expandProperty DnsHostName |选择对象-expandProperty DnsHostName | Export-Csv -Path C:\Logs\SSL.csv -NoTypeInformation
-
我已经用格式更新了代码,它现在抱怨同样的错误。
-
请注意,我们更喜欢这里的技术写作风格。我们轻轻地劝阻问候,希望你能帮助,谢谢,提前感谢,感谢信,问候,亲切的问候,签名,请你能帮助,聊天材料和缩写 txtspk,恳求,你多久了被卡住、投票建议、元评论等。只需解释您的问题,并展示您尝试过的内容、预期的内容以及实际发生的情况。
标签: powershell scripting active-directory windows-scripting