我试图在报告中添加ping失败的服务器,但是异常不会将结果添加到datagridview ..我在哪里出错?在datagridview中没有为ping失败的服务器添加异常
function Test-Ping {
$Servers = Get-Content $textboxServerName.txt
$Set = @()
foreach ($Server in $Servers) {
try {
$Set += Test-Connection -ComputerName $Server -Count 1 |
Select -Property @{n='ServerName';e={$_.PSComputerName}},
@{n='IPv4';e={$_.IPV4Address}},
@{n='IPv6';e={$_.IPV6Address}},
@{n='ProtocolAddress';e={$_.ProtocolAddress}} -ErrorAction Stop
} catch [System.Exception] {
$Set += @{n='ServerName';e={$_.PSComputerName}},
@{n='IPv4';e={N/A}},
@{n='IPv6';e={N/A}},
@{n='ProtocolAddress';e={N/A}}
}
$table = ConvertTo-DataTable -InputObject $Set -FilterWMIProperties
Load-DataGridView -DataGridView $datagridview1 -Item $table
}
}
安斯加尔感谢您在这一切帮助..我已经建立了基于给出建议的功能,得到了如下错误.. – Aamir
ERROR :以“9”为参数调用“添加”的例外情况t(s):“当控件是数据绑定时,无法以编程方式将行添加到DataGridView的行集合中。” – Aamir
[google:// + + + +控件+ +数据绑定时,Rows +无法+以编程方式+添加+ + DataGridView的+行+集合+(http://www.google.com/search ?q =行+不能+编程+添加+ + DataGridView的+行+集合+当+控制+是+数据绑定) –