-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAzureConnection.ps1
52 lines (42 loc) · 1.84 KB
/
AzureConnection.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
$Cred = Get-AutomationPSCredential -Name 'AzureCredential'
# Connect to Azure
$AzureAccount = Add-AzureAccount -Credential $Cred
$AzureSubscriptionName = Get-AutomationVariable –Name ‘AzureSubscriptionName’
Select-AzureSubscription -SubscriptionName $AzureSubscriptionName
# Specify the parameters to be used by the script
$AEProtocol = "TCP"
$AELocalPort = 80
$AEPublicPort = 80
$AEName = "Port 80 for HTTP"
$VMGUID = "7a1069c6-c1d6-49c5-8c5d-33bfce8dd183"
workflow OpenPort80
{
param (
[Object]$RecoveryPlanContext
)
$Cred = Get-AutomationPSCredential -Name 'AzureCredential'
# Connect to Azure
$AzureAccount = Add-AzureAccount -Credential $Cred
$AzureSubscriptionName = Get-AutomationVariable –Name ‘AzureSubscriptionName’
Select-AzureSubscription -SubscriptionName $AzureSubscriptionName
# Specify the parameters to be used by the script
$AEProtocol = "TCP"
$AELocalPort = 80
$AEPublicPort = 80
$AEName = "Port 80 for HTTP"
$VMGUID = "7a1069c6-c1d6-49c5-8c5d-33bfce8dd183"
#Read the VM GUID from the context
$VM = $RecoveryPlanContext.VmMap.$VMGUID
if ($VM -ne $null)
{
# Invoke pipeline commands within an InlineScript
$EndpointStatus = InlineScript {
# Invoke the necessary pipeline commands to add an Azure Endpoint to a specified Virtual Machine
# This set of commands includes: Get-AzureVM | Add-AzureEndpoint | Update-AzureVM (including necessary parameters)
$Status = Get-AzureVM -ServiceName $Using:VM.CloudServiceName -Name $Using:VM.RoleName | `
Add-AzureEndpoint -Name $Using:AEName -Protocol $Using:AEProtocol -PublicPort $Using:AEPublicPort -LocalPort $Using:AELocalPort | `
Update-AzureVM
Write-Output $Status
}
}
}