Arrays Powershell阵列和刷新

Arrays Powershell阵列和刷新,arrays,powershell,Arrays,Powershell,我目前正在编写一个脚本,它使用get service | select Displayname来显示正在运行的内容 然而,我遇到了麻烦 我用这个: function Getcurrent-AD { $Script:current_active_d = get-service | select Displayname $array = New-Object System.Collections.ArrayList $array.AddRange($current_active_d)

我目前正在编写一个脚本,它使用get service | select Displayname来显示正在运行的内容

然而,我遇到了麻烦

我用这个:

function Getcurrent-AD 
{
  $Script:current_active_d = get-service | select Displayname
  $array = New-Object System.Collections.ArrayList
  $array.AddRange($current_active_d)
  $current_output.DataSource = $array
  $objForm.refresh()
}

创建一个数组并将其放入一个数据表单网格,然后该网格将写入我正在单击的主机,但我只能让它工作,以便它在控制台中显示所选的第一个项目

请帮忙

试试这个:

$current_output.Add_Click({
    $value = $current_output.Rows[$current_output.CurrentRow.Index].Cells['DisplayName'].Value
    Write-Host $value
})
试试这个:

$current_output.Add_Click({
    $value = $current_output.Rows[$current_output.CurrentRow.Index].Cells['DisplayName'].Value
    Write-Host $value
})

谢谢,但我恐怕遇到了这个错误-无法索引到空数组中。在C:\Temp\ADXv0.300.ps1:170字符:30+$value=$moveright.Rows这是我的表单:$CurrnOutOuts=新的对象Stask.Wistop.Ford.DavaGIDVIEW $ $MOVELIGHT = No.ObjyStask.WONDOWS.FANS .Button右移动是我所使用的按钮的名称,然后如果您认为它对您有帮助,可以考虑接受它。我用正确的控制对象更新了我的答案。谢谢,但是我恐怕已经收到了。是错误-无法索引到空数组。在C:\Temp\ADXv0.300.ps1:170 char:30+$value=$moveright.Rows这是我的表单:$CurrnOutOuts=新的对象Stask.Wistop.Fas.StaseDigaGIDVIEW $ $MOVELIGHT = No.ObjyStask.WiDOWS.FANS .Button右移动是我所使用的按钮的名称,然后如果你认为它对你有帮助,可以考虑接受它。我用正确的控制对象更新了我的答案。