-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew-DummyArray.ps1
58 lines (51 loc) · 1.81 KB
/
New-DummyArray.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<#
<-New-DummyArray->
.SYNOPSIS
Creates a dummy array for testing purposes
.DESCRIPTION
If for testing purposes a array is required this can be used to create a dummy array
.PARAMETER AmountOfObjects
Defines mount of created objects. default is 10
.PARAMETER ItemsPerObject
Amount of keys that are need in the objects. default is 10
.PARAMETER CharPerItem
Characters per value.default is 10
.EXAMPLE
New-DummyArray -AmountOfObjects 15 -ItemsPerObject 20 -CharPerItem 20
// returns array with 15 object each with 20 keypair values and 20 characters per value
.NOTES
This function uses the New-Random String function, if you do not want to import tmhe fuction make sure you set the $Value variable in script
#>
function New-DummyArray {
[CmdletBinding()]
Param(
[Parameter(
Mandatory = $true)][Int]$AmountOfObjects,
[Parameter(
Mandatory = $true)][Int]$ItemsPerObject,
[Parameter(
Mandatory = $false)][Int]$CharPerItem
)
if (!$AmountOfObjects) {
$AmountOfObjects = 10
}
if (!$ItemsPerObject) {
$ItemsPerObject = 10
}
[System.Collections.ArrayList]$Objects = @()
for ($i = 0; $i -lt $AmountOfObjects; $i++) {
$Object = [PSCustomObject]@{}
for ($n = 0; $n -lt $ItemsPerObject; $n++) {
if ($CharPerItem) {
$Value = New-RandomString -Length $CharPerItem #set something else if you do not want to import this function
}
else {
$Value = New-RandomString #set something else if you do not want to import this function
}
$Object | Add-Member -MemberType NoteProperty -Name ('Field' + ($n + 1)) -Value $Value
}
$Objects.Add($Object) | Out-Null
Remove-Variable 'Object'
}
return $Objects
}