@@ -5,13 +5,17 @@ function New-AzVm {
5
5
[CmdletBinding (SupportsShouldProcess = $true )]
6
6
param (
7
7
[Parameter (Mandatory = $true , Position = 0 )][string ] $Name = " VM" ,
8
- [Parameter ()][PSCredential ] $Credential ,
9
- [Parameter ()][string ] $ImageName = " Win2012R2Datacenter" ,
8
+
10
9
[Parameter ()][string ] $ResourceGroupName ,
11
10
[Parameter ()][string ] $Location ,
11
+
12
12
[Parameter ()][string ] $VirtualNetworkName ,
13
13
[Parameter ()][string ] $PublicIpAddressName ,
14
- [Parameter ()][string ] $SecurityGroupName
14
+ [Parameter ()][string ] $SecurityGroupName ,
15
+
16
+ [Parameter ()][PSCredential ] $Credential ,
17
+ [Parameter ()][string ] $ImageName = " Win2012R2Datacenter" ,
18
+ [Parameter ()][string ] $Size = " Standard_DS1_v2"
15
19
)
16
20
17
21
PROCESS {
@@ -29,7 +33,14 @@ function New-AzVm {
29
33
$sgi );
30
34
31
35
# the purpouse of the New-AzVm cmdlet is to create (not get) a VM so $name is $null.
32
- $vmi = [VirtualMachine ]::new($null , $nii , $rgi , $Credential , $ImageName , $images );
36
+ $vmi = [VirtualMachine ]::new(
37
+ $null ,
38
+ $nii ,
39
+ $rgi ,
40
+ $Credential ,
41
+ $ImageName ,
42
+ $images ,
43
+ $Size );
33
44
34
45
# infer a location
35
46
$locationi = [Location ]::new();
@@ -48,14 +59,24 @@ function New-AzVm {
48
59
$resourceGroup = $rgi.GetOrCreate ($createParams );
49
60
$vmResponse = $vmi.Create ($createParams );
50
61
51
- New-PsObject @ {
52
- ResourceId = $resourceGroup.ResourceId ;
53
- Response = $vmResponse ;
54
- }
62
+ return [ PSAzureVm ]::new(
63
+ $resourceGroup.ResourceId ,
64
+ $Name
65
+ );
55
66
}
56
67
}
57
68
}
58
69
70
+ class PSAzureVm {
71
+ [string ] $ResourceGroupId ;
72
+ [string ] $Name ;
73
+
74
+ PSAzureVm([string ] $resourceGroupId , [string ] $name ) {
75
+ $this.ResourceGroupId = $resourceGroupId ;
76
+ $this.Name = $name ;
77
+ }
78
+ }
79
+
59
80
class Location {
60
81
[int ] $Priority ;
61
82
[string ] $Value ;
@@ -258,20 +279,23 @@ class VirtualMachine: AzureObject {
258
279
[pscredential ] $Credential ;
259
280
[string ] $ImageName ;
260
281
[object ] $Images ;
282
+ [string ] $Size ;
261
283
262
284
VirtualMachine(
263
285
[string ] $name ,
264
286
[NetworkInterface ] $networkInterface ,
265
287
[ResourceGroup ] $resourceGroup ,
266
288
[PSCredential ] $credential ,
267
289
[string ] $imageName ,
268
- [object ] $images ):
290
+ [object ] $images ,
291
+ [string ] $size ):
269
292
base($name , @ ($networkInterface , $resourceGroup )) {
270
293
271
294
$this.Credential = $credential ;
272
295
$this.ImageName = $imageName ;
273
296
$this.NetworkInterface = $networkInterface ;
274
297
$this.Images = $images ;
298
+ $this.Size = $size ;
275
299
}
276
300
277
301
[object ] GetInfo() {
@@ -282,29 +306,28 @@ class VirtualMachine: AzureObject {
282
306
$networkInterfaceInstance = $this.NetworkInterface.GetOrCreate ($p );
283
307
284
308
if (-not $this.Credential ) {
285
- $this.Credential = Get-Credential
309
+ $this.Credential = Get-Credential ;
286
310
}
287
311
288
- $vmImage = $this.Images | Where-Object { $_.Name -eq $this.ImageName } | Select-Object - First 1
312
+ $vmImage = $this.Images | Where-Object { $_.Name -eq $this.ImageName } | Select-Object - First 1 ;
289
313
if (-not $vmImage ) {
290
- throw " Unknown image: " + $this.ImageName
314
+ throw " Unknown image: " + $this.ImageName ;
291
315
}
292
316
293
- $vmSize = " Standard_DS2"
294
- $vmConfig = New-AzureRmVMConfig - VMName $p.Name - VMSize $vmSize
295
- $vmComputerName = $p.Name + " Computer"
317
+ $vmConfig = New-AzureRmVMConfig - VMName $p.Name - VMSize $this.Size ;
318
+ $vmComputerName = $p.Name + " Computer" ;
296
319
switch ($vmImage.Type ) {
297
320
" Windows" {
298
321
$vmConfig = $vmConfig | Set-AzureRmVMOperatingSystem `
299
322
- Windows `
300
323
- ComputerName $vmComputerName `
301
- - Credential $this.Credential
324
+ - Credential $this.Credential ;
302
325
}
303
326
" Linux" {
304
327
$vmConfig = $vmConfig | Set-AzureRmVMOperatingSystem `
305
328
- Linux `
306
329
- ComputerName $vmComputerName `
307
- - Credential $this.Credential
330
+ - Credential $this.Credential ;
308
331
}
309
332
}
310
333
0 commit comments