0

Its a short question but i have some problems understanding customobjects in powershell.

I tried to create a list but was not able to do make it work i have to less knowledge for this.

$applist = [PSCustomObject]@{
    appname = $listitem
}
#somecode
do{
    $appname = Read-Host "Which App you want to delete: [OneConnect]"
    $listitem += "*$appname*"
    #add $listitem to $applist except it is like **
    $counterT++
}while($appname -notlike "")

$applist

i want to display $applist all the entries except the clear one

It should look like

*Zune*

*OneConnect*

Kevin
  • 193
  • 1
  • 4
  • 16
  • 2
    is there a reason you are creating a custom object that has the list in it? the more usual way would be to make a list as such ... [*grin*] – Lee_Dailey Apr 08 '19 at 07:44
  • i have a problem understanding Arrays and lists in anyway in powershell, but somehow it would be crusial to get this done in my head – Kevin Apr 08 '19 at 07:47
  • 1
    i see that you have been pointed to the excellent post by KevMar about arrays & collections in general. i highly recommend his "everything" posts ... [*grin*] – Lee_Dailey Apr 08 '19 at 08:24

1 Answers1

1

You are missing the scope. Just declare the custom object within that will result in the display but you have to work on the logic of how you wish to see them (format). Give the below a try and you should be able to see the entries of your read-host

#somecode
do{
    $appname = Read-Host "Which App you want to delete: [OneConnect]"
    $listitem += "*$appname*"
    #add $listitem to $applist except it is like **
    $counterT++

    $applist = [PSCustomObject]@{
    appname = $listitem
}
}while($appname -notlike "")

$applist
Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45
  • is there a way to get my "logic" working i find it somehow complicated, and to have it in rows not columns – Kevin Apr 08 '19 at 07:41
  • Enclosing an appname in asterisks makes IMO only sense in a comparison with `-like` not as appending to $listitem of unknown type. –  Apr 08 '19 at 07:42
  • but this is how i actually need it in further use I'll edit my post for clarification – Kevin Apr 08 '19 at 07:45
  • @Kevin: I haven't checked the logic. I just rectified the scope part for which you were not getting values. For logic part, I need to see what exactly the time of apps that you are expecting there. See for me, the PSCustomObject is not at all needed because what you are doing is simply can be added in an arraylist – Ranadip Dutta Apr 08 '19 at 07:45
  • this is where my "failure" is coming from, i dont have any idea of how arrays, list or the custom objects are working properly this is complicated as hell for me but never got it explaind properly – Kevin Apr 08 '19 at 07:53
  • 1
    @Kevin: Understood the pain. Please go through [THIS](https://powershellexplained.com/2018-10-15-Powershell-arrays-Everything-you-wanted-to-know/). spend sometime. – Ranadip Dutta Apr 08 '19 at 07:55
  • 1
    Thank you for the link share i will read it through definitly maybe it will end the confusin in my head – Kevin Apr 08 '19 at 07:59
  • @Kevin: Acceptance or Upvote would be appreciable if the answer helps you. Else unnecessarily I do not wish to keep it – Ranadip Dutta Apr 08 '19 at 08:03