1

I'm currently experimenting and trying to get this code:

$processnames = Get-Process | select name 
foreach ($processname in $processnames)
{
[void]$AD_list_current.Items.Add($processnames)

}

to output in a listbox. It outputs as it is but for some reason it keeps displaying in the listbox as:enter image description here

Does anyone know why this is?

It would be greatly apprechiated.

Thank you

3 Answers 3

3

Here's a shorter way to add all process names:

$list.Items.AddRange( (Get-Process | select name) )
Sign up to request clarification or add additional context in comments.

Comments

2

Try this:

[void]$AD_list_current.Items.Add($($processnames))

Comments

1

You are adding $processnames instead of $processname to your list.

That's an array.

As per Joey's comment, the default ToString() method will show the type name, which is System.Object.

2 Comments

It's an array and the default ToString() implementation yields the type name. Nothing in particular to do with interpreting as object.
I added $processname instead of $processnames and it worked. Thanks all for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.