-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew-AzureRMResourceGroupDeployment.ps1
71 lines (56 loc) · 2.12 KB
/
New-AzureRMResourceGroupDeployment.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
Param(
$DeploymentName = '04 JuraAzureMSDN_DSC_IISinstall',
$AzureUserName = "[email protected]",
$AzurePassword = "Password01",
$VMAdminUsername = "norma.finch",
$VMAdminPassword = "Password01",
$resourcegroupname = 'juracorporation',
$JSONTemplate = "D:\Box Sync\Technical Skills\Products\Azure (PAYG)\Azure IAAS - Azure VMs (PAYG)\Automation\ARM Templates\04 JuraAzureMSDN_DSC_IISinstall\azureVMdeploy.json",
$JSONparamtemplate = "D:\Box Sync\Technical Skills\Products\Azure (PAYG)\Azure IAAS - Azure VMs (PAYG)\Automation\ARM Templates\04 JuraAzureMSDN_DSC_IISinstall\azureVMdeploy.parameters.json"
)
#New-AzureRmResourceGroupDeployment -Name $DeploymentName -ResourceGroupName $resourcegroup -TemplateUri D:\ARMTemplates\JuraStandardAzureVM.json
Write-verbose "Logging into Azure"
#Create a Credential block and connect to to Azure
#$cred = [System.Management.Automation.PSCredential]::new($AzureUserName,($AzurePassword | ConvertTo-SecureString -AsPlainText -Force))
#import-module Azurerm
Login-AzureRmAccount | Out-Null
Write-verbose "Storing paths for JSON files"
#Path to JSON Files
$templatefile = "$JSONTemplate"
$templateparamfile = "$JSONParamTemplate"
$deployparams = @{
Name = "ArmDeploy-$(get-date -Format ddMMyyyy_HH-mm-ss)"
ResourceGroupName = $resourcegroupname
TemplateFile = $templatefile
Verbose = $true
}
Write-verbose "Calling ARM to deploy VM"
$VMpass = $VMAdminPassword | ConvertTo-SecureString -AsPlainText -Force
#$DJPass = $DomainJoinPass | ConvertTo-SecureString -AsPlainText -Force
if($templateparamfile)
{
Try
{
Write-Verbose "Deploying Resources with parameters file $templateparamfile"
$arm = New-AzureRmResourceGroupDeployment @deployparams -TemplateParameterFile $templateparamfile -Mode Incremental -ErrorAction Stop
$status = $arm.ProvisioningState
}
Catch
{
$status = "Failed"
}
}
Else
{
Try
{
$arm = New-AzureRmResourceGroupDeployment @deployparams -adminpassword $pass -Mode Incremental -ErrorAction Stop
$status = $arm.ProvisioningState
}
Catch
{
$status = "Failed"
}
}
Return $status