Create multiple instances of custom Powershell object -


I am creating a new object in PowerShell Script, or actually an object type. I want to make several examples of this object. How do I do this?

I am working on the code given below, it appears that all the examples in the array refer to the same object, which has the same values.

  Set # output object $ project type = new object system. Object $ project type | Add-member-memberType noteproperty-value "" -Name project $ project type | Add-member -membertip notefront-value "" -name category $ project type. | Add-member -membertype noteproperty -value "" -name Description # Import data $ data = import-csv $ stop input-terrorism # Create a normal collection object $ projects = @ () # data exchange ($ line in $ data) Parse {$ Project = $ projectType $ project.Project = $ line.Id $ project.Category = $ line.Naam $ project.Description = $ line $ Projects + = $ project} $ Projects | Export-CSV output.csv -NoTypeInformation-Force  

OK, the new object for the new object, instead of being a reference type $ projectType in your code, refers to the same object is the change code:

Define the # Output Object Function New Project {New Object PSOBigECT-Property @ {Project = '' Category = '' Description = ''}} # Parse Data $ Project = @ () Foreign Currency (Line $ 1..9) {$ Project = New-Project $ project.Project = $ line $ project.Category = $ line $ project.Description = $ line $ projects + = $ project} # $ Continue the projects

Instead of using the function new-project , you can only take your body in the loop in this special case, eg . $ project = New object PSObject ... . But if you make your "projects" somewhere else, then it will be useful even if this ceremony is there.


Comments