You can create a new instance this way:
New-Object -TypeName "UrlTestModel" -Property @{
Name = "string"
Url = "string"
TestInProd = "string"
}
Or define a constructor in your class:
class UrlTestModel
{
[String]$Name
[String]$Url
[String]$TestInProd
UrlTestModel([string]$name, [string]$url, [string]$testInProd) {
$this.Name = $name
$this.Url = $url
$this.TestInProd = $testInProd
}
}
And then create a new instance like this:
[UrlTestModel]::new("string", "string", "string")
You can read more about it in about_Classes.
Lists are basically created by using the comma operator:
$list = [UrlTestModel]::new("name1", "url1", "true"), [UrlTestModel]::new("name2", "url2", "false")
# or
$a = New-Object -TypeName UrlTestModel -Property @{Name = "string"; Url = "string"; TestInProd = "string" }
$b = New-Object -TypeName UrlTestModel -Property @{Name = "string"; Url = "string"; TestInProd = "string" }
$list = $a, $b
Iterate over a list using the ForEach-Object cmdlet or the foreach statement:
$list | ForEach-Object {
# this is the current item:
$_
}
# or
foreach ($item in $list) {
# ...
}
$list |ForEach-Object { <# Do somthing with $_ #> }orforeach($item in $list){ <# do something with $item here #> }