-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplit-DevicesIntoCategories.ps1
42 lines (35 loc) · 1.5 KB
/
Split-DevicesIntoCategories.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
# Create an array of objects
$array = Import-Csv -Path '<CSVLocation>'
# Calculate the total number of items in the array
$TotalArrayItems = $array.count
# Calculate the percentage of items to be split into each category
$testCategoryPercentage = 10
$pilotCategoryPercentage = 20
$productionCategoryPercentage = 70
# Calculate the number of items to be split into each category
$testCategoryItems = [Math]::Round($TotalArrayItems * $testCategoryPercentage/100)
$pilotCategoryItems = [Math]::Round($TotalArrayItems * $pilotCategoryPercentage/100)
$productionCategoryItems = [Math]::Round($TotalArrayItems * $productionCategoryPercentage/100)
# Create empty arrays for each category
$testCategory = @()
$pilotCategory = @()
$productionCategory = @()
# Iterate over the array and add the items to the respective categories
for($i=0;$i -lt $TotalArrayItems;$i++) {
if(($i -lt $testCategoryItems) -and ([System.String]::IsNullOrEmpty($array[$i].category))) {
$testCategory += $array[$i]
}
elseif(($i -lt ($testCategoryItems + $pilotCategoryItems)) -and ([System.String]::IsNullOrEmpty($array[$i].category))) {
$pilotCategory += $array[$i]
}
else {
$productionCategory += $array[$i]
}
}
foreach($item in $testCategory){$item.category = "Test"}
foreach($item in $pilotCategory){$item.category = "Pilot"}
foreach($item in $productionCategory){$item.category = "Production"}
$outputArray = @()
$outputArray += $testCategory
$outputArray += $pilotCategory
$outputArray += $productionCategory