![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Creating a steam of custom objects in a loop I'm looking at creating a stream of custom objects, sorting them, then processing further. Select-Object gives a flavour of what I would like to do. However in this case I want to create an object whose properties are not a subset of predefined classes. I'll create the properties in code (in a loop) and emit a collection of the objects. Can anyone point me to an example for doing that? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Creating a steam of custom objects in a loop Hi Mike, > Can anyone point me to an example for doing that? Not sure if it's what you are looking for: $array=@() for($idx=0;$idx -lt 10;++$idx) { $o=1 | select Name, Lastname $o.Name="Foo $idx"; $o.Lastname="Bar $idx"; $array+=$o; } $array| sort lastname -desc cu Max |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Creating a steam of custom objects in a loop "Mike Gale" <MikeGale@discussions.microsoft.com> wrote in message news:B2AF2386-306B-4CA2-989B-6196D8930523@microsoft.com... > I'm looking at creating a stream of custom objects, sorting them, then > processing further. > > Select-Object gives a flavour of what I would like to do. However in this > case I want to create an object whose properties are not a subset of > predefined classes. I'll create the properties in code (in a loop) and > emit > a collection of the objects. > > Can anyone point me to an example for doing that? Here's some code I use in a script to create an object from a hashtable of propname (key) / value (value) pairs: if ($props.Count -gt 0) { $statusObj = new-object system.management.automation.psobject $statusObj.psobject.typenames[0] = "Custom.Tfs.VersionControl.Status" foreach ($key in $props.keys) { add-member -input $statusObj -MemberType NoteProperty $key $props["$key"] } Write-Output $statusObj $props.Clear() } -- Keith |
My System Specs![]() |
| | #4 (permalink) |
| | RE: Creating a steam of custom objects in a loop Thanks to Max and Keith both. I adopted a PSObject style approach and used Add-Member. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| loop through all ad objects | PowerShell | |||
| PowerShell Custom Objects | PowerShell | |||
| Using entlib 2 from custom objects | PowerShell | |||
| Creating custom objects with add-member | PowerShell | |||
| Info: Can you create your own objects with custom properties. | PowerShell | |||