I want to create an object based on the cmd command
(openfiles /query /s SERVERNAME)
I can get all the properties in the fashion I want by doing a split, and the below works on adding the last item in the array to the object…but how can i get them all listed in the object so i could do a command like…
You’re on the right track. You’re not trying to create AN objects, though, you need to create MULTIPLE OBJECTS. One object for each whatever it is you want.
You’d normally do this in a function, and the function uses Write-Output to emit each object, as it’s created, to the pipeline. You could then pipe them to something else.
Then use $objectarray += $object inside the loop as well
In the end $objectarray will have an array of objects.
**This is the way I used to do things too, but no longer ** Since being on this forum, and reading a lot about Powershell I now write functions as Don Jones suggested. Maybe look into this solution when you have the time.