Powershell数组和刷新

问题描述:

我目前正在编写一个使用get-service的脚本|选择显示名称以显示正在运行的内容。Powershell数组和刷新

但是,我遇到了麻烦。

我使用这个:

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() 
} 

$moveright.Add_Click({ 

$selectedRow = $current_output.CurrentRowIndex 
    if (($procid=$Script:current_active_d["$selectedRow"].displayname)) { 
       write-host $procid 
     } 


} 
) 

创建一个数组,并把它放在一个数据网格的形式,然后写入到主机在那里我一下,但我可以只有让它工作,才能在控制台中显示所选的第一个项目。

请帮忙!

试试这个:

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

感谢,但我怕我得到这个错误 - 无法索引空数组。在C:\ Temp \ ADXv0.300.ps1:170 char:30 + $ value = $ moveright.Rows [ obious 2012-04-25 10:36:42

+0

$ moveright是datagridview控件? – 2012-04-25 11:28:32

+0

这里是我的表单:$ current_output = New-Object System.Windows.Forms.DataGridView - $ moveright = New-Object System.Windows.Forms.Button - 右移是我正在使用的按钮的名称 – obious 2012-04-25 11:40:07