forked from seansp-zz/Framework-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_variant_name_list.ps1
84 lines (72 loc) · 2.83 KB
/
create_variant_name_list.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#
# Create a set of macines based on variants. Variants are different machine types (standard_d2_v2), so a set of variant
# machines all share the same base VHD image, but are (potentially) using different hardware configurations.#
# Copies VHDs that have booted as expected to the test location where they will be prepped
# for Azure automation
#
# Author: John W. Fawcett, Principal Software Development Engineer, Microsoft
#
param (
[Parameter(Mandatory=$false)] [string] $Flavors="",
[Parameter(Mandatory=$false)] [string] $requestedNames = "",
[Parameter(Mandatory=$false)] [string] $location = "",
[Parameter(Mandatory=$false)] [string] $suffix = ""
)
$Flavors = $Flavors.Trim()
$requestedNames = $requestedNames.Trim()
$location = $location.Trim()
$suffix = $suffix.Trim()
[System.Collections.ArrayList]$vmNames_array
$vmNameArray = {$vmNames_array}.Invoke()
$vmNameArray.Clear()
if ($requestedNames -match ",") {
$vmNameArray = $requestedNames.Split(',')
} else {
$vmNameArray = $requestedNames
}
[System.Collections.ArrayList]$flavors_array
$flavorsArray = {$flavors_array}.Invoke()
$flavorsArray.Clear()
if ($Flavors -match ",") {
$flavorsArray = $Flavors.Split(',')
} else {
$flavorsArray = $Flavors
}
if ($flavorsArray.Count -eq 1 -and $flavorsArray[0] -eq "" ) {
Write-Host "Must specify at least one VM Flavor to build.. Unable to process this request."
exit 1
}
. "C:\Framework-Scripts\common_functions.ps1" > $null
. "C:\Framework-Scripts\secrets.ps1" > $null
$firstOne = $true
# Write-Verbose "Before the loop, names count is $allNamesCount"
# Write-Verbose "Before the loop, flavors count is $allFlavorsCount"
# Write-Verbose "listString = $listString"
foreach ($vmName in $vmNameArray) {
$vmName = $vmName.Trim()
# Write-Verbose "Setting flavors for |$vmName|"
foreach ($oneFlavor in $flavorsArray) {
$oneFlavor = $oneFlavor.Trim()
# Write-Verbose "Adding the flavor information for $oneFlavor"
$regionSuffix = ("---" + $location + "-" + $oneFlavor.ToLower()) -replace " ","-"
$regionSuffix = $regionSuffix -replace "_","-"
$imageName = $vmName + $regionSuffix
$imageName = $imageName + $suffix
$imageName = $imageName -replace ".vhd",""
$theAddition = $imageName.Trim()
# write-verbose "Adding in |$theAddition|"
if ($firstOne -eq $true) {
$listString = $listString + $theAddition + ","
# write-verbose "String is now |$listString|"
} else {
$listString = $theAddition + ","
# write-verbose "String is now |$listString|"
$firstOne = $true
}
# Write-Verbose "listString = $listString"
}
}
# write-verbose "String is now |$listString|"
$listString = $listString -Replace ".$",""
# write-verbose "String is now |$listString|"
$listString.Trim()