1
1
function New-AzVm {
2
2
[CmdletBinding ()]
3
- param ()
3
+ param (
4
+ [PSCredential ] $credential ,
5
+ [string ] $name = " vmTest"
6
+ )
4
7
5
8
PROCESS {
6
- # Images
7
- <#
8
- Write-Host "Load images..."
9
- $jsonImages = Get-Content -Path "images.json" | ConvertFrom-Json
10
- Write-Host "done"
11
- #>
12
-
13
- # an array of @{ Type = ...; Name = ...; Image = ... }
14
- # $images = $jsonImages.outputs.aliases.value.psobject.Properties | ForEach-Object {
15
- $images = $staticImages.psobject.Properties | ForEach-Object {
16
- # e.g. "Linux"
17
- $type = $_.Name
18
- $_.Value.psobject.Properties | ForEach-Object {
19
- New-Object - TypeName psobject - Property @ {
20
- # e.g. "Linux"
21
- Type = $type ;
22
- # e.g. "CentOs"
23
- Name = $_.Name ;
24
- # e.g. @{ publisher = "OpenLogic"; offer = "CentOS"; sku = "7.3"; version = "latest" }
25
- Image = $_.Value
26
- }
27
- }
9
+ if (-not $credential ) {
10
+ $credential = Get-Credential
28
11
}
29
12
30
13
# Find VM Image
@@ -104,25 +87,21 @@ function New-AzVm {
104
87
105
88
# VM
106
89
# $vmCredentials = Get-Credential
107
- $vm = @ { Name = " vmTest " ; Size = " Standard_DS2" }
90
+ $vm = @ { Name = $name ; Size = " Standard_DS2" }
108
91
$vmConfig = New-AzureRmVMConfig - VMName $vm.Name - VMSize $vm.Size
109
92
$vmComputer = $vm.Name
110
- $vmComputerPassword = " E5v7e9!@%f" ;
111
- $vmComputerUser = " special" ;
112
- $password = ConvertTo-SecureString $vmComputerPassword - AsPlainText - Force;
113
- $cred = New-Object System.Management.Automation.PSCredential ($vmComputerUser , $password );
114
93
switch ($vmImage.Type ) {
115
94
" Windows" {
116
95
$vmConfig = $vmConfig | Set-AzureRmVMOperatingSystem `
117
96
- Windows `
118
97
- ComputerName $vmComputer `
119
- - Credential $cred
98
+ - Credential $credential
120
99
}
121
100
" Linux" {
122
101
$vmConfig = $vmConfig | Set-AzureRmVMOperatingSystem `
123
102
- Linux `
124
103
- ComputerName $vmComputer `
125
- - Credential $cred
104
+ - Credential $credential
126
105
}
127
106
}
128
107
@@ -222,4 +201,22 @@ $staticImages = New-PsObject @{
222
201
};
223
202
}
224
203
204
+ # Images
205
+ # an array of @{ Type = ...; Name = ...; Image = ... }
206
+ # $images = $jsonImages.outputs.aliases.value.psobject.Properties | ForEach-Object {
207
+ $images = $staticImages.psobject.Properties | ForEach-Object {
208
+ # e.g. "Linux"
209
+ $type = $_.Name
210
+ $_.Value.psobject.Properties | ForEach-Object {
211
+ New-Object - TypeName psobject - Property @ {
212
+ # e.g. "Linux"
213
+ Type = $type ;
214
+ # e.g. "CentOs"
215
+ Name = $_.Name ;
216
+ # e.g. @{ publisher = "OpenLogic"; offer = "CentOS"; sku = "7.3"; version = "latest" }
217
+ Image = $_.Value
218
+ }
219
+ }
220
+ }
221
+
225
222
Export-ModuleMember - Function New-AzVm
0 commit comments