Skip to content

Commit d63a3e9

Browse files
no password
1 parent 4507204 commit d63a3e9

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

experiments/Compute.Experiments/AzureRM.Compute.Experiments.Tests.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ $clientSecret = ConvertTo-SecureString $credentials.clientSecret -AsPlainText -F
1010
$pscredentials = New-Object System.Management.Automation.PSCredential($credentials.applicationId, $clientSecret)
1111
Login-AzureRmAccount -ServicePrincipal -Credential $pscredentials -TenantId $credentials.tenantId | Out-Null
1212

13-
$vm = New-AzVm
13+
$vmComputerPassword = $credentials.vmPassword;
14+
$vmComputerUser = $credentials.vmUser;
15+
$password = ConvertTo-SecureString $vmComputerPassword -AsPlainText -Force;
16+
$vmCredential = New-Object System.Management.Automation.PSCredential ($vmComputerUser, $password);
17+
18+
# $vm = New-AzVm
19+
$vm = New-AzVm -Credential $vmCredential
1420

1521
$vm
1622

experiments/Compute.Experiments/AzureRM.Compute.Experiments.psm1

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,13 @@
11
function 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+
225222
Export-ModuleMember -Function New-AzVm

0 commit comments

Comments
 (0)