forked from scriptrunner/ActionPacks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew-AzVM.ps1
147 lines (125 loc) · 5.45 KB
/
New-AzVM.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
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
145
146
147
#Requires -Version 5.0
#Requires -Modules Az.Compute
<#
.SYNOPSIS
Creates a virtual machine
.DESCRIPTION
.NOTES
This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
the use and the consequences of the use of this freely available script.
PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
© ScriptRunner Software GmbH
.COMPONENT
Requires Module Az
Requires Library script AzureAzLibrary.ps1
.LINK
https://github.com/scriptrunner/ActionPacks/blob/master/Azure/Compute
.Parameter Name
[sr-en] Specifies a name for the virtual machine
[sr-de] Name der virtuellen Maschine
.Parameter ResourceGroupName
[sr-en] Specifies the name of a resource group
[sr-de] Name der resource group die die virtuelle Maschine enthält
.Parameter Location
[sr-en] Specifies the location for the virtual machine
[sr-de] Location der virtuellen Maschine
.Parameter AdminCredential
[sr-en] The administrator credentials for the VM
[sr-de] Administratoranmeldeinformationen für die VM
.Parameter DataDiskSizeInGb
[sr-en] Specifies the sizes of data disks in GB
[sr-de] Größe von Datenträgern in GB
.Parameter EnableUltraSSD
[sr-en] Use UltraSSD disks for the vm
[sr-de] UltraSSD-Datenträger verwenden für die virtuelle Maschine
.Parameter Image
[sr-en] The friendly image name upon which the VM will be built
[sr-de] Imagename, auf dem die VM erstellt wird
.Parameter AllocationMethod
[sr-en] The IP allocation method for the public IP which will be created for the VM
[sr-de] IP-Zuweisungsmethode für die öffentliche IP-Adresse
.Parameter SecurityGroupName
[sr-en] The name of a new (or existing) network security group (NSG) for the created VM to use.
If not specified, a name will be generated
[sr-de] Name einer neuen (oder vorhandenen) Netzwerksicherheitsgruppe (NSG) für die erstellte VM.
Wenn nicht angegeben, wird ein Name generiert
.Parameter SubnetName
[sr-en] The name of a new (or existing) subnet for the created VM to use.
If not specified, a name will be generated
[sr-de] Name eines neuen (oder vorhandenen) Subnetzes
Wenn nicht angegeben, wird ein Name generiert
.Parameter VirtualNetworkName
[sr-en] The name of a new (or existing) virtual network for the created VM to use.
If not specified, a name will be generated
[sr-de] Name eines neuen (oder vorhandenen) virtuellen Netzwerks
Wenn nicht angegeben, wird ein Name generiert
.Parameter Size
[sr-en] The Virtual Machine Size
[sr-de] Größe der virtuellen Maschine
#>
param(
[Parameter(Mandatory = $true)]
[string]$Name,
[Parameter(Mandatory = $true)]
[pscredential]$AdminCredential,
[string]$ResourceGroupName,
[int]$DataDiskSizeInGb,
[switch]$EnableUltraSSD,
[ValidateSet('Win2016Datacenter', 'Win2012R2Datacenter', 'Win2012Datacenter', 'Win2008R2SP1', 'UbuntuLTS', 'CentOS', 'CoreOS', 'Debian', 'openSUSE-Leap', 'RHEL', 'SLES')]
[string]$Image = "Win2016Datacenter",
[ValidateSet('Static', 'Dynamic')]
[string]$AllocationMethod,
[string]$Location,
[string]$SecurityGroupName,
[string]$SubnetName,
[string]$VirtualNetworkName,
[string]$Size = 'Standard_DS1_v2'
)
Import-Module Az.Compute
try{
[string[]]$Properties = @('Name','StatusCode','ResourceGroupName','Id','VmId','Location','ProvisioningState','DisplayHint')
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
'Confirm' = $false
'Credential' = $AdminCredential
'Name' = $Name
'Image' = $Image
'EnableUltraSSD' = $EnableUltraSSD}
if([System.String]::IsNullOrWhiteSpace($ResourceGroupName) -eq $false){
$cmdArgs.Add('ResourceGroupName',$ResourceGroupName)
}
if([System.String]::IsNullOrWhiteSpace($Location) -eq $false){
$cmdArgs.Add('Location',$Location)
}
if([System.String]::IsNullOrWhiteSpace($SecurityGroupName) -eq $false){
$cmdArgs.Add('SecurityGroupName',$SecurityGroupName)
}
if([System.String]::IsNullOrWhiteSpace($SubnetName) -eq $false){
$cmdArgs.Add('SubnetName',$SubnetName)
}
if([System.String]::IsNullOrWhiteSpace($VirtualNetworkName) -eq $false){
$cmdArgs.Add('VirtualNetworkName',$VirtualNetworkName)
}
if([System.String]::IsNullOrWhiteSpace($AllocationMethod) -eq $false){
$cmdArgs.Add('AllocationMethod',$AllocationMethod)
}
if($PSBoundParameters.ContainsKey('Size') -eq $true){
$cmdArgs.Add('Size',$Size)
}
if($DataDiskSizeInGb -gt 0){
$cmdArgs.Add('DataDiskSizeInGb',$DataDiskSizeInGb)
}
$ret = New-AzVM @cmdArgs | Select-Object $Properties
if($SRXEnv) {
$SRXEnv.ResultMessage = $ret
}
else{
Write-Output $ret
}
}
catch{
throw
}
finally{
}