Results are shown as @{...}

Welcome Forums General PowerShell Q&A Results are shown as @{...}

This topic contains 2 replies, has 2 voices, and was last updated by

5 years, 9 months ago.

  • Author
  • #4706

    Points: 1
    Rank: Member

    Hi guys,

    I am still a beginner with Powershell and I am trying to create a Windows Forms application.

    This is what I need: a toolstripcombobox, where its items are updated according to a variable.

    Let me show you a summary:

    $Location = dir *.txt | select Basename

    I have 2 textfiles in the same directory as the Powershell script, called File1.txt and File2.txt.

    I would like my combobox items to have the name of those files, but instead they always appear as



    (See attachment)

    How can I make them to be called simply File1 and File2?


  • #4711

    Points: 1
    Rank: Member

    I figured it out in another way:

    dir *.txt | sort Basename| ForEach-Object {$toolstripcombobox1.Items.AddRange($_.basename)}

    Thanks for your effort!

    If somebody could still tell me what was wrong in my first post, please tell me!


    Have a nice day!

  • #4813

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    When you see output as @{this=that;those=these}, or something similar, it's because you've taken multiple objects (a collection) and tried to convert them all to a single string. That formatting is just how PowerShell deals with that situation.

    In your original, it's because you were selecting the BaseName property of multiple objects. That's always a collection of objects. In your revision, you used ForEach-Object to go through them one at a time. So rather than converting the collection to a single string (which PowerShell can't really do all that well), it converts a single object to a single string (which it does just fine).

The topic ‘Results are shown as @{...}’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort