Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,8 @@ samples/databases/wide-world-importers/workload-drivers/order-insert/Multithread
/samples/features/epm-framework/5.0/2Reporting/PolicyReports/bin/Debug
/samples/features/epm-framework/5.0/2Reporting/PolicyReports/PolicyDashboard - Backup.rdl
/samples/features/epm-framework/5.0/2Reporting/PolicyReports/PolicyDashboardFiltered.rdl.data

# Certificates
*.pem
*.p12

Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ To run this sample, you need the following prerequisites.

**Software prerequisites:**

1. PowerShell 5.1
2. Azure PowerShell 5.4.2 or higher
1. PowerShell 5.1 or PowerShell Core 6.0
2. Azure PowerShell Az module

**Azure prerequisites:**

Expand All @@ -40,7 +40,7 @@ To run this sample, you need the following prerequisites.

## Run this sample

Run the script below from Windows PowerShell or Azure Cloud Shell
Run the script below from PowerShell or Azure Cloud Shell

```powershell

Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,69 @@
$parameters = $args[0]
$scriptUrlBase = $args[1]

$subscriptionId = $parameters['subscriptionId']
$resourceGroupName = $parameters['resourceGroupName']
$virtualMachineName = $parameters['virtualMachineName']
$virtualNetworkName = $parameters['virtualNetworkName']
$managementSubnetName = $parameters['subnetName']
$administratorLogin = $parameters['administratorLogin']
$administratorLoginPassword = $parameters['administratorLoginPassword']

$scriptUrlBase = $args[1]
$administratorLogin = $parameters['administratorLogin']
$administratorLoginPassword = $parameters['administratorLoginPassword']

if($virtualMachineName -eq '' -or $virtualMachineName -eq $null) {
if ($virtualMachineName -eq '' -or ($null -eq $virtualMachineName)) {
$virtualMachineName = 'Jumpbox'
Write-Host "VM Name: 'Jumpbox'." -ForegroundColor Green
}

if($managementSubnetName -eq '' -or $managementSubnetName -eq $null) {
if ($managementSubnetName -eq '' -or ($null -eq $managementSubnetName)) {
$managementSubnetName = 'Management'
Write-Host "Using subnet 'Management' to deploy jumpbox VM." -ForegroundColor Green
}

function VerifyPSVersion
{
Write-Host "Verifying PowerShell version, must be 5.0 or higher."
if($PSVersionTable.PSVersion.Major -ge 5)
{
Write-Host "PowerShell version verified." -ForegroundColor Green
function VerifyPSVersion {
Write-Host "Verifying PowerShell version."
if ($PSVersionTable.PSEdition -eq "Desktop") {
if (($PSVersionTable.PSVersion.Major -ge 6) -or
(($PSVersionTable.PSVersion.Major -eq 5) -and ($PSVersionTable.PSVersion.Minor -ge 1))) {
Write-Host "PowerShell version verified." -ForegroundColor Green
}
else {
Write-Host "You need to install PowerShell version 5.1 or heigher." -ForegroundColor Red
Break;
}
}
else {
if ($PSVersionTable.PSVersion.Major -ge 6) {
Write-Host "PowerShell version verified." -ForegroundColor Green
}
else {
Write-Host "You need to install PowerShell version 6.0 or heigher." -ForegroundColor Red
Break;
}
}
else
{
Write-Host "You need to install PowerShell version 5.0 or heigher." -ForegroundColor Red
Break;
}

function EnsureAzModule {
Write-Host "Checking if Az module is imported."
$module = Get-Module Az
If ($null -eq $module) {
try {
Import-Module Az -ErrorAction Stop
Write-Host "Module Az imported." -ForegroundColor Green
}
catch {
Install-Module Az -AllowClobber
Write-Host "Module Az installed." -ForegroundColor Green
}
} else {
Write-Host "Module Az imported." -ForegroundColor Green
}
}

function EnsureLogin ()
{
$context = Get-AzureRmContext
If($null -eq $context.Subscription)
{
function EnsureLogin () {
$context = Get-AzContext
If ($null -eq $context.Subscription) {
Write-Host "Sign-in..."
If($null -eq (Login-AzureRmAccount -ErrorAction SilentlyContinue -ErrorVariable Errors))
{
If ($null -eq (Connect-AzAccount -ErrorAction SilentlyContinue -ErrorVariable Errors)) {
Write-Host ("Sign-in failed: {0}" -f $Errors[0].Exception.Message) -ForegroundColor Red
Break
}
Expand All @@ -54,16 +76,14 @@ function SelectSubscriptionId {
$subscriptionId
)
Write-Host "Selecting subscription '$subscriptionId'..."
$context = Get-AzureRmContext
If($context.Subscription.Id -ne $subscriptionId)
{
Try
{
Write-Host "Switching subscription $context.Subscription.Id to '$subscriptionId'." -ForegroundColor Green
Select-AzureRmSubscription -SubscriptionId $subscriptionId -ErrorAction Stop | Out-null
$context = Get-AzContext
If ($context.Subscription.Id -ne $subscriptionId) {
Try {
$currentSubscriptionId = $context.Subscription.Id
Write-Host "Switching subscription $currentSubscriptionId to '$subscriptionId'." -ForegroundColor Green
Select-AzSubscription -SubscriptionId $subscriptionId -ErrorAction Stop | Out-null
}
Catch
{
Catch {
Write-Host "Subscription selection failed: $_" -ForegroundColor Red
Break
}
Expand All @@ -76,59 +96,52 @@ function LoadVirtualNetwork {
$resourceGroupName,
$virtualNetworkName
)
Write-Host("Loading virtual network '{0}' in resource group '{1}'." -f $virtualNetworkName, $resourceGroupName)
$virtualNetwork = Get-AzureRmVirtualNetwork -ResourceGroupName $resourceGroupName -Name $virtualNetworkName -ErrorAction SilentlyContinue
$id = $virtualNetwork.Id
If($null -ne $id)
{
Write-Host "Virtual network with id $id is loaded." -ForegroundColor Green
If($virtualNetwork.VirtualNetworkPeerings.Count -gt 0) {
Write-Host "Virtual network is loaded, but it should not have peerings." -ForegroundColor Red
}
return $virtualNetwork
}
else
{
Write-Host "Virtual network $virtualNetworkName cannot be found." -ForegroundColor Red
Break
Write-Host("Loading virtual network '{0}' in resource group '{1}'." -f $virtualNetworkName, $resourceGroupName)
$virtualNetwork = Get-AzVirtualNetwork -ResourceGroupName $resourceGroupName -Name $virtualNetworkName -ErrorAction SilentlyContinue
$id = $virtualNetwork.Id
If ($null -ne $id) {
Write-Host "Virtual network with id $id is loaded." -ForegroundColor Green
If ($virtualNetwork.VirtualNetworkPeerings.Count -gt 0) {
Write-Host "Virtual network is loaded, but it should not have peerings." -ForegroundColor Red
}
return $virtualNetwork
}
else {
Write-Host "Virtual network $virtualNetworkName cannot be found." -ForegroundColor Red
Break
}
}

function SetVirtualNetwork
{
function SetVirtualNetwork {
param($virtualNetwork)

Write-Host "Applying changes to the virtual network."
Try
{
Set-AzureRmVirtualNetwork -VirtualNetwork $virtualNetwork -ErrorAction Stop | Out-Null
Try {
Set-AzVirtualNetwork -VirtualNetwork $virtualNetwork -ErrorAction Stop | Out-Null
}
Catch
{
Catch {
Write-Host "Failed to configure Virtual Network: $_" -ForegroundColor Red
}
}

function ConvertCidrToUint32Array
{
function ConvertCidrToUint32Array {
param($cidrRange)
$cidrRangeParts = $cidrRange.Split("/")
$ipParts = $cidrRangeParts[0].Split(".")
$ipnum = ([Convert]::ToUInt32($ipParts[0]) -shl 24) -bor `
([Convert]::ToUInt32($ipParts[1]) -shl 16) -bor `
([Convert]::ToUInt32($ipParts[2]) -shl 8) -bor `
[Convert]::ToUInt32($ipParts[3])
([Convert]::ToUInt32($ipParts[1]) -shl 16) -bor `
([Convert]::ToUInt32($ipParts[2]) -shl 8) -bor `
[Convert]::ToUInt32($ipParts[3])

$maskbits = [System.Convert]::ToInt32($cidrRangeParts[1])
$mask = 0xffffffff
$mask = $mask -shl (32 -$maskbits)
$mask = $mask -shl (32 - $maskbits)
$ipstart = $ipnum -band $mask
$ipend = $ipnum -bor ($mask -bxor 0xffffffff)
return @($ipstart, $ipend)
}

function ConvertUInt32ToIPAddress
{
function ConvertUInt32ToIPAddress {
param($uint32IP)
$v1 = $uint32IP -band 0xff
$v2 = ($uint32IP -shr 8) -band 0xff
Expand All @@ -137,16 +150,13 @@ function ConvertUInt32ToIPAddress
return "$v4.$v3.$v2.$v1"
}

function CalculateNextAddressPrefix
{
function CalculateNextAddressPrefix {
param($virtualNetwork, $prefixLength)
Write-Host "Calculating address prefix with length $prefixLength..."
$startIPAddress = 0
ForEach($addressPrefix in $virtualNetwork.AddressSpace.AddressPrefixes)
{
ForEach ($addressPrefix in $virtualNetwork.AddressSpace.AddressPrefixes) {
$endIPAddress = (ConvertCidrToUint32Array $addressPrefix)[1]
If($endIPAddress -gt $startIPAddress)
{
If ($endIPAddress -gt $startIPAddress) {
$startIPAddress = $endIPAddress
}
}
Expand All @@ -156,57 +166,57 @@ function CalculateNextAddressPrefix
return $addressPrefixResult
}

function CalculateVpnClientAddressPoolPrefix
{
function CalculateVpnClientAddressPoolPrefix {
param($gatewaySubnetPrefix)
Write-Host "Calculating VPN client address pool prefix."
If($gatewaySubnetPrefix.StartsWith("10."))
{
If ($gatewaySubnetPrefix.StartsWith("10.")) {
return "192.168.0.0/24"
}
else
{
else {
return "172.16.0.0/24"
}

}

VerifyPSVersion
EnsureAzModule
EnsureLogin
SelectSubscriptionId -subscriptionId $subscriptionId

$virtualNetwork = LoadVirtualNetwork -resourceGroupName $resourceGroupName -virtualNetworkName $virtualNetworkName

$subnets = $virtualNetwork.Subnets.Name

If($false -eq $subnets.Contains($managementSubnetName))
{
If ($false -eq $subnets.Contains($managementSubnetName)) {
Write-Host "$managementSubnetName is not one of the subnets in $subnets" -ForegroundColor Yellow
Write-Host "Creating subnet $managementSubnetName ($managementSubnetPrefix) in the VNet..." -ForegroundColor Green
$managementSubnetPrefix = CalculateNextAddressPrefix $virtualNetwork 28
Write-Host "Creating subnet $managementSubnetName ($managementSubnetPrefix) in the virtual network ..." -ForegroundColor Green

$virtualNetwork.AddressSpace.AddressPrefixes.Add($managementSubnetPrefix)
Add-AzureRmVirtualNetworkSubnetConfig -Name $managementSubnetName -VirtualNetwork $virtualNetwork -AddressPrefix $managementSubnetPrefix | Out-Null
Add-AzVirtualNetworkSubnetConfig -Name $managementSubnetName -VirtualNetwork $virtualNetwork -AddressPrefix $managementSubnetPrefix | Out-Null

SetVirtualNetwork $virtualNetwork
Write-Host "Added subnet $managementSubnetName into VNet." -ForegroundColor Green
} else {
Write-Host "The subnet $managementSubnetName exists in the VNet." -ForegroundColor Green
Write-Host "Added subnet $managementSubnetName into virtual network." -ForegroundColor Green
}
else {
Write-Host "The subnet $managementSubnetName exists in the virtual network." -ForegroundColor Green
}

Write-Host

# Start the deployment
Write-Host "Starting deployment..."
Write-Host "Deployment will take about 20m." -ForegroundColor Yellow

$templateParameters = @{
virtualNetworkName = $virtualNetworkName
managementSubnetName = $managementSubnetName
virtualMachineName = $virtualMachineName
administratorLogin = $administratorLogin
administratorLoginPassword = $administratorLoginPassword
location = $virtualNetwork.Location
virtualNetworkName = $virtualNetworkName
managementSubnetName = $managementSubnetName
virtualMachineName = $virtualMachineName
administratorLogin = $administratorLogin
administratorLoginPassword = $administratorLoginPassword
}

New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri ($scriptUrlBase+'/azuredeploy.json?t='+ [DateTime]::Now.Ticks) -TemplateParameterObject $templateParameters
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri ($scriptUrlBase + '/azuredeploy.json?t=' + [DateTime]::Now.Ticks) -TemplateParameterObject $templateParameters

Write-Host "Deployment completed."
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ To run this sample, you need the following prerequisites.

**Software prerequisites:**

1. PowerShell 5.1
2. Azure PowerShell 5.4.2 or higher
1. PowerShell 5.1 or PowerShell Core 6.0
2. Azure PowerShell Az module

**Linux prerequisites**
1. strongSwan

**Azure prerequisites:**

Expand All @@ -40,7 +43,7 @@ To run this sample, you need the following prerequisites.

## Run this sample

Run the script below from Windows PowerShell
Run the script below from PowerShell

```powershell

Expand Down
Loading