11function New-AzVm {
22 [CmdletBinding ()]
3- param ()
3+ param (
4+ [PSCredential ] $credential ,
5+ [string ] $name = " vmTest"
6+ )
47
58 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
2811 }
2912
3013 # Find VM Image
@@ -104,25 +87,21 @@ function New-AzVm {
10487
10588 # VM
10689 # $vmCredentials = Get-Credential
107- $vm = @ { Name = " vmTest " ; Size = " Standard_DS2" }
90+ $vm = @ { Name = $name ; Size = " Standard_DS2" }
10891 $vmConfig = New-AzureRmVMConfig - VMName $vm.Name - VMSize $vm.Size
10992 $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 );
11493 switch ($vmImage.Type ) {
11594 " Windows" {
11695 $vmConfig = $vmConfig | Set-AzureRmVMOperatingSystem `
11796 - Windows `
11897 - ComputerName $vmComputer `
119- - Credential $cred
98+ - Credential $credential
12099 }
121100 " Linux" {
122101 $vmConfig = $vmConfig | Set-AzureRmVMOperatingSystem `
123102 - Linux `
124103 - ComputerName $vmComputer `
125- - Credential $cred
104+ - Credential $credential
126105 }
127106 }
128107
@@ -222,4 +201,22 @@ $staticImages = New-PsObject @{
222201 };
223202}
224203
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+
225222Export-ModuleMember - Function New-AzVm
0 commit comments