Exported on 07-Oct-2021 22:01:12
Parameters
1 - Install Azure Az PowerShell Module
This step installs the Azure Az PowerShell Module
The Blueprint first gets the Execution Policy of the current PowerShell session.
Then, checks if the Execution Policy is set to Unrestricted.
If it's not, it then sets the Execution Policy to Unrestricted for the current session.
Next, it checks if the Az PowerShell module is installed.
If it's not installed, it then goes ahead to install the module.
Login as user {Attune Node Credential} on node {Attune Node}
#Region for ExecutionPolicy
# Get Execution Policy of the current process
$Script:ProcessEP = Get-ExecutionPolicy -Scope Process
#Get the value of the Execution Policy and save it in the Variable
$Script:ValueProcessEP = ($Script:ProcessEP).value__
# Check if the Execution Policy of the process is set to Unrestricted
if ($Script:ValueProcessEP -eq 0) {
# Write the message
Write-Output "Execution Policy is already set to Unrestricted for the Process"
# Check if the Execution Policy of the process is already set
}else{
# Set the ExecutionPolicy of the Process to Unrestricted
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted -Force -Confirm:$false
# Checks if the Execution Policy has been set
if ((Get-ExecutionPolicy -Scope Process).value__ -eq 0) {
# Write the message
Write-Output "Execution Policy is now set to Unrestricted for the Process"
}
}
#EndRegion for ExecutionPolicy
#Region Check if Az Module is installed
#Region if module is installed, update module if version is not up to Version "4.1.13.0"
if($null -ne (Get-InstalledModule -Name Az -ErrorVariable +ErrorAzV -ErrorAction SilentlyContinue)) {
# Get the Az module installed and save it in a variable
$Script:GetAzModule = Get-InstalledModule -Name Az -ErrorVariable +ErrorAzV -ErrorAction SilentlyContinue
# Writes a message to the screen
Write-Output "Az PowerShell Module exists ... checking ..."
# Gets the build number for the Az Module
$Script:AzModuleBuild = ($Script:GetAzModule).Version
# Checks the build number to meet requirements
if($Script:AzModuleBuild -like "*6.3.0*") {
# Saves and converts Module version name to a variable
$Script:OutVersion = ((($Script:GetAzModule).Version)).tostring()
# Writes a message to the screen
Write-Output "Az Module Version $Script:OutVersion meets the minimum requirement."
# Check if the build version is on 13
}else{
# Writes a message to the screen
Write-Output "Updating the Az PowerShell Module..."
# Uppdates the AzPowerShell Module to the latest version
Update-Module -Name Az -Confirm:$false -Force
# Writes a message to the screen
Write-Output "Az PowerShell Module is updated :)"
}
#EndRegion if the module is installed, update module if the version is not up to Version "4.1.13.0"
#Region If the module is not installed, install it
}else{
# Writes a message to the screen
Write-Output "Az PowerShell Module is not installed"
# Writes a message to the screen
Write-Output "Az PowerShell Module is installing..."
# Install Az Powershell Module
Install-Module -Name Az -MaximumVersion "6.3.0" -Scope "CurrentUser" -AllowClobber:$true -Confirm:$false -Force
# Writes a message to the screen
Write-Output "Az PowerShell Module is installed :)"
}
#EndRegion If the module is not installed, install it
2 - Start Azure VM
This step starts the Azure Virtual Machine(s)
The Blueprint first gets the Execution Policy of the current PowerShell session.
Then checks if the Execution Policy is set to Unrestricted.
If it's not, it then sets the Execution Policy to Unrestricted for the current session.
Next, the AzPowerShell module is imported to the current session.
Then the values below are set:
- UserName: This is the Username of the Azure Administrator corresponding to the
AzureUserName
set in the Inputs Tab. - PasswordString: This is the Password of the Azure Administrator corresponding to the
AzurePassword
set in the Inputs Tab. - AzureVmNames: This holds an array of VM(s) name(s) in Azure corresponding to the
AzureVmNames
set in the Inputs Tab.
Next, a connection to Azure is made.
Then it loops through the values of the Azure VM Names and starts the virtual machines.
Finally, the Azure PowerShell session is disconnected.
Login as user {Attune Node Credential} on node {Attune Node}
#Region for ExecutionPolicy
# Get Execution Policy of the current process
$Script:ProcessEP = Get-ExecutionPolicy -Scope Process
#Get the value of the Execution Policy and save it in the Variable
$Script:ValueProcessEP = ($Script:ProcessEP).value__
# Check if the Execution Policy of the process is set to Unrestricted
if ($Script:ValueProcessEP -eq 0) {
# Write the message
Write-Output "Execution Policy is already set to Unrestricted for the Process"
# Check if the Execution Policy of the process is already set
}else{
# Set the ExecutionPolicy of the Process to Unrestricted
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted -Force -Confirm:$false
# Checks if the Execution Policy has been set
if ((Get-ExecutionPolicy -Scope Process).value__ -eq 0) {
# Write the message
Write-Output "Execution Policy is now set to Unrestricted for the Process"
}
}
#EndRegion for ExecutionPolicy
#Region Start Azure VM
# Import Module for Az PowerShell
Import-Module -Name Az
#Region assign variables
# Save accesskey to this Variable
$Script:UserName = "{azureusername.value}"
# Save secretkey to this variable
$Script:PasswordString = "{azurepassword.value}"
# List of VM names
$Script:AzureVmNames = {azurevmnames.value}
#EndRegion assign variables
#Region for Connection to Azure
# Set the password and convert it to secure string to the variable
$Script:Password = ConvertTo-SecureString $Script:PasswordString -AsPlainText -Force
# set the credentials to the variable
$Script:UserCredential = New-Object System.Management.Automation.PSCredential ($Script:UserName,$Script:Password)
# Connect using set credentials to Azure
Connect-AzAccount -Credential $Script:UserCredential
#EndRegion for Connection to Azure
# Loop through the hash table for the Names of the VM
foreach ($item in $Script:AzureVmNames) {
# Get the Azure VM
$Script:AzVm = Get-AzVM -VMName ($item)
# Write the message
Write-Output "The Azure VM '$($item)' in is starting....."
# Start the Azure VM
Start-AzVM -ResourceGroupName $Script:AzVm.ResourceGroupName -Name $Script:AzVm.Name -NoWait -Confirm:$false
}
#EndRegion Start Azure VM
#Region Disconnect the Azure session
Disconnect-AzAccount
#EndRegion Disconnect the Azure session
Using Attune to start Azure Virtual Machine
This Blueprint is used for starting single or multiple Azure Virtual Machines.
An Azure Virtual Machines is the Azure infrastructure as a service (IaaS) used to deploy virtual machines, it's commonly shorted to VMs with nearly any VM server workload that you want.
They provide on-demand and scalable computing resources with usage-based pricing.
Pre-Blueprint Attune setup
AzureVmNames Syntax:
@('VMOne', 'VMTwo', 'VMThree')
Blueprint Steps