1
+ # Requires -Version 5.0
2
+ # Requires -Modules Az .Compute
3
+
4
+ <#
5
+ . SYNOPSIS
6
+ Creates a Azure virtual machine
7
+
8
+ . DESCRIPTION
9
+
10
+ . NOTES
11
+ This PowerShell script was developed and optimized for ScriptRunner. The use of the scripts requires ScriptRunner.
12
+ The customer or user is authorized to copy the script from the repository and use them in ScriptRunner.
13
+ The terms of use for ScriptRunner do not apply to this script. In particular, ScriptRunner Software GmbH assumes no liability for the function,
14
+ the use and the consequences of the use of this freely available script.
15
+ PowerShell is a product of Microsoft Corporation. ScriptRunner is a product of ScriptRunner Software GmbH.
16
+ © ScriptRunner Software GmbH
17
+
18
+ . COMPONENT
19
+ Requires Module Az
20
+ Requires Library script AzureAzLibrary.ps1
21
+ Requires the library script StatisticLib.ps1
22
+
23
+ . LINK
24
+ https://github.com/scriptrunner/ActionPacks/blob/master/Statistics/Samples
25
+
26
+ . Parameter Name
27
+ [sr-en] Specifies a name for the virtual machine
28
+ [sr-de] Name der virtuellen Maschine
29
+
30
+ . Parameter ResourceGroupName
31
+ [sr-en] Specifies the name of a resource group
32
+ [sr-de] Name der resource group die die virtuelle Maschine enthält
33
+
34
+ . Parameter Location
35
+ [sr-en] Specifies the location for the virtual machine
36
+ [sr-de] Ort der virtuellen Maschine
37
+
38
+ . Parameter AdminCredential
39
+ [sr-en] The administrator credentials for the VM
40
+ [sr-de] Administratoranmeldeinformationen für die VM
41
+
42
+ . Parameter DataDiskSizeInGb
43
+ [sr-en] Specifies the sizes of data disks in GB
44
+ [sr-de] Größe von Datenträgern in GB
45
+
46
+ . Parameter EnableUltraSSD
47
+ [sr-en] Use UltraSSD disks for the vm
48
+ [sr-de] UltraSSD-Datenträger verwenden für die virtuelle Maschine
49
+
50
+ . Parameter Image
51
+ [sr-en] The friendly image name upon which the VM will be built
52
+ [sr-de] Imagename, auf dem die VM erstellt wird
53
+
54
+ . Parameter AllocationMethod
55
+ [sr-en] The IP allocation method for the public IP which will be created for the VM
56
+ [sr-de] IP-Zuweisungsmethode für die öffentliche IP-Adresse
57
+
58
+ . Parameter SecurityGroupName
59
+ [sr-en] The name of a new (or existing) network security group (NSG) for the created VM to use.
60
+ If not specified, a name will be generated
61
+ [sr-de] Name einer neuen (oder vorhandenen) Netzwerksicherheitsgruppe (NSG) für die erstellte VM.
62
+ Wenn nicht angegeben, wird ein Name generiert
63
+
64
+ . Parameter SubnetName
65
+ [sr-en] The name of a new (or existing) subnet for the created VM to use.
66
+ If not specified, a name will be generated
67
+ [sr-de] Name eines neuen (oder vorhandenen) Subnetzes
68
+ Wenn nicht angegeben, wird ein Name generiert
69
+
70
+ . Parameter VirtualNetworkName
71
+ [sr-en] The name of a new (or existing) virtual network for the created VM to use.
72
+ If not specified, a name will be generated
73
+ [sr-de] Name eines neuen (oder vorhandenen) virtuellen Netzwerks
74
+ Wenn nicht angegeben, wird ein Name generiert
75
+
76
+ . Parameter CostReduction
77
+ [sr-en] Cost saving through execution per ScriptRunner, in seconds
78
+ [sr-de] Zeitersparnis, in Sekunden
79
+ #>
80
+
81
+ param (
82
+ [Parameter (Mandatory = $true )]
83
+ [string ]$Name ,
84
+ [Parameter (Mandatory = $true )]
85
+ [pscredential ]$AdminCredential ,
86
+ [string ]$ResourceGroupName ,
87
+ [int ]$DataDiskSizeInGb ,
88
+ [switch ]$EnableUltraSSD ,
89
+ [ValidateSet (' Win2016Datacenter' , ' Win2012R2Datacenter' , ' Win2012Datacenter' , ' Win2008R2SP1' , ' UbuntuLTS' , ' CentOS' , ' CoreOS' , ' Debian' , ' openSUSE-Leap' , ' RHEL' , ' SLES' )]
90
+ [string ]$Image = " Win2016Datacenter" ,
91
+ [ValidateSet (' Static' , ' Dynamic' )]
92
+ [string ]$AllocationMethod ,
93
+ [string ]$Location ,
94
+ [string ]$SecurityGroupName ,
95
+ [string ]$SubnetName ,
96
+ [string ]$VirtualNetworkName ,
97
+ [int ]$CostReduction = 1200
98
+ )
99
+
100
+ Import-Module Az
101
+
102
+ try {
103
+ [hashtable ]$cmdArgs = @ {' ErrorAction' = ' Stop'
104
+ ' Confirm' = $false
105
+ ' Credential' = $AdminCredential
106
+ ' Name' = $Name
107
+ ' Image' = $Image
108
+ ' EnableUltraSSD' = $EnableUltraSSD }
109
+
110
+ if ([System.String ]::IsNullOrWhiteSpace($ResourceGroupName ) -eq $false ){
111
+ $cmdArgs.Add (' ResourceGroupName' , $ResourceGroupName )
112
+ }
113
+ if ([System.String ]::IsNullOrWhiteSpace($Location ) -eq $false ){
114
+ $cmdArgs.Add (' Location' , $Location )
115
+ }
116
+ if ([System.String ]::IsNullOrWhiteSpace($SecurityGroupName ) -eq $false ){
117
+ $cmdArgs.Add (' SecurityGroupName' , $SecurityGroupName )
118
+ }
119
+ if ([System.String ]::IsNullOrWhiteSpace($SubnetName ) -eq $false ){
120
+ $cmdArgs.Add (' SubnetName' , $SubnetName )
121
+ }
122
+ if ([System.String ]::IsNullOrWhiteSpace($VirtualNetworkName ) -eq $false ){
123
+ $cmdArgs.Add (' VirtualNetworkName' , $VirtualNetworkName )
124
+ }
125
+ if ([System.String ]::IsNullOrWhiteSpace($AllocationMethod ) -eq $false ){
126
+ $cmdArgs.Add (' AllocationMethod' , $AllocationMethod )
127
+ }
128
+ if ($DataDiskSizeInGb -gt 0 ){
129
+ $cmdArgs.Add (' DataDiskSizeInGb' , $DataDiskSizeInGb )
130
+ }
131
+
132
+ $ret = New-AzVM @cmdArgs
133
+ LogExecution - CostSavingsSeconds $CostReduction
134
+
135
+ if ($SRXEnv ) {
136
+ $SRXEnv.ResultMessage = $ret
137
+ }
138
+ else {
139
+ Write-Output $ret
140
+ }
141
+ }
142
+ catch {
143
+ throw
144
+ }
145
+ finally {
146
+ }
0 commit comments