我正在尝试测试网络连接,如果它很好,请告诉我它已找到。未找到ELSE写主机,并将该计算机导出为CSV。但是,我只是得到了错误"测试与计算机的连接失败:由于缺乏资源而出错。"在无法获得连接的计算机上。测试连接不能以这种方式工作吗? =" True"正在为我工作。以下是我的代码:
foreach ($computer in $Computers)
$computername = $computer.Computers
$testConnection = Test-Connection $computername
IF ($testConnection = "True")
{
{
Write-Host "$computername found"
}
ElSE
{
Write-Host "$computername does not have CCleaner installed." #| Export-Csv C:\Users\jcheng\Desktop\Scripts\PingTestLog.txt -Append
}
{
答案 0 :(得分:0)
试一试
foreach ($computer in $Computers)
$computername = $computer.Computers
$testConnection = Test-Connection $computername
If (($testConnection -ne "") -or ($testconnection -ne $null){
Write-Host "$computername found"
}
Else{
Write-Host "$computername does not have CCleaner installed." #| Export-Csv C:\Users\jcheng\Desktop\Scripts\PingTestLog.txt -Append
}
我会检查这个:$computer.Computers
,看看它是否实际上正在返回您要查找的属性。
作为旁注,请确保您的CCleaner版本比5.33更新:)最近遭到破坏