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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
| -
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
-
!
-
-
|
!
-
!
-
-
!
-
|
-
-
|
-
|
!
!
!
-
|
-
|
!
!
-
|
!
-
|
!
-
!
-
-
|
|
|
!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
!
-
!
-
!
|
-
|
!
|
|
!
|
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]$SubscriptionName,
[Parameter(Mandatory=$True, HelpMessage="It must be pre-built.")]
[string]$VNetName,
[Parameter(Mandatory=$True, HelpMessage="It must be pre-built.")]
[string]$SubnetName,
[Parameter(Mandatory=$True, HelpMessage="It must be pre-built.")]
[string]$CurrentStorageName,
[Parameter(Mandatory=$True, HelpMessage="New or existing either.")]
[string]$CloudServiceName,
[Parameter(Mandatory=$True, HelpMessage="Cloud services location(e.g, Japan East, West Japan, East Asia, West US, North Europe, ...)")]
[string]$Location,
[Parameter(Mandatory=$True)]
[string]$AdminUserName,
[Parameter(Mandatory=$True)]
[string]$AdminPassword,
[Parameter(Mandatory=$False)]
[boolean]$AlwaysYes = $False,
[Parameter(Mandatory=$False)]
[string]$VMImage = @(Get-AzureVMImage | Where-Object -Property Label -Match "Windows Server 2012 R2 Datacenter.* 2016").ImageName[-1],
[Parameter(Mandatory=$False)]
[string]$InstanceSize = "Small",
[Parameter(Mandatory=$False)]
[string[]]$VMNames = @("vm1", "vm2"),
[Parameter(Mandatory=$False, HelpMessage="Duplication is not permitted.")]
[int32[]]$RDPPorts = @(55200, 55201),
[Parameter(Mandatory=$False, HelpMessage="New or existing either.")]
[string]$AvailabilitySetName = "as" + (Get-Date -Format "yyyyMMddHHmmssfff").ToString()
)
function Log($text) {
return (Get-Date -Format "yyyy/MM/dd HH:mm:ss").ToString() + " $($text)"
}
"< Deploy on Azure >"
"Deploy with the following settings."
($MyInvocation.MyCommand.Parameters ).Keys | %{
$val = (Get-Variable -Name $_ -EA SilentlyContinue).Value
if ($val.length -gt 0) {
if ($_ -match "password") {
" $($_) = ***"
} else {
" $($_) = $($val)"
}
}
}
if (!$AlwaysYes) {
$in = Read-Host "Is it OK?(Y/N) [default Y] "
if (($in -ine "Y") -and ($in -ine "")) {
Exit
}
}
Select-AzureSubscription `
-SubscriptionName $SubscriptionName `
-Current `
-ErrorAction Stop
Set-AzureSubscription `
-SubscriptionName $SubscriptionName `
-CurrentStorageAccount $CurrentStorageName `
-ErrorAction Stop
Log("VM(v1) creation start...")
$VMs = @()
for ($i = 0; $i -lt $VMNames.Length; ++$i) {
New-AzureQuickVM `
-ImageName $VMImage `
-ServiceName $CloudServiceName `
-Name $VMNames[$i] `
-Windows `
-AdminUsername $AdminUserName `
-Password $AdminPassword `
-Location $Location `
-InstanceSize $InstanceSize `
-SubnetNames $SubnetName `
-VNetName $VNetName `
-AvailabilitySetName $AvailabilitySetName `
-NoWinRMEndpoint `
-WaitForBoot `
-ErrorAction Stop
Log("New-AzureQuickVM done($($VMNames[$i]))")
$VM = Get-AzureVM -ServiceName $CloudServiceName -Name $VMNames[$i] -ErrorAction Stop
Remove-AzureEndpoint -VM $VM -Name "RemoteDesktop" -ErrorAction Stop
Add-AzureEndpoint -VM $VM -Name "RemoteDesktop" -Protocol "tcp" -PublicPort $RDPPorts[$i] -LocalPort 3389 -ErrorAction Stop
$VM | Update-AzureVM -ErrorAction Stop
$VMs += $VM
}
Log("...VM(v1) criation end")
|