Advertisement
Combreal

MakeCustomObjFromLoop.ps1

Jan 9th, 2023
1,070
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $dopeObjs=@()
  2. $propertyNames = "Name", "Age", "Sexe"
  3.  
  4. $obj = New-Object -TypeName PSObject
  5. $propertyNames | foreach {
  6.     $obj | Add-Member -NotePropertyName $_ -NotePropertyValue $(Get-Random -Minimum 1 -Maximum 10)
  7. }
  8. $dopeObjs += $obj
  9.  
  10. $obj = New-Object -TypeName PSObject
  11. $propertyNames | foreach {
  12.     $obj | Add-Member -NotePropertyName $_ -NotePropertyValue $(Get-Random -Minimum 1 -Maximum 10)
  13. }
  14. $dopeObjs += $obj
  15.  
  16. $dopeObjs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement