Assigning Specific Public IP Addresses With Azure Automation Runbook

Microsoft Power Automate Flows, UI Flows, & Automation Runbooks: Part Three of a series


The last blog post in this series covered how I provisioned my Robotic Process Automation (RPA) test environment using Azure Automation runbooks. In this post, I will use an additional runbook to assign the newly provisioned virtual machine a specific public IP address.


I previously defined a public IP address that is whitelisted as an approved source address to access the test Salesforce environment needed for the RPA flow. This was configured for security reasons. It was also very beneficial having the same public IP address to RDP into for troubleshooting. This public IP address was used in a previous project and resides in a different resource group called Research. The following code is the PowerShell script I wrote for the automation runbook that applies this public IP to the NIC of the newly created virtual machine.


#Note: The Research resource group contains the allowed Public IP that is added to the new VM in a different resource group.
[Parameter (Mandatory= $true)]
[string]$ResourceGroupName = "Research",
[string]$VirtualNetworkName = "$vendor-VirtualNetwork",
[string]$PublicIPName = "$vendor-PublicIP",
[string]$ipconfigname = 'ipconfig1',
[string]$NicName = "$vendor-Nic",
[string]$SubnetName = 'default'

#Service Principal Authentication

Connect-AzAccount -CertificateThumbprint $Thumbprint -ApplicationId $ApplicationId -
Tenant $TenantId -ServicePrincipal

#Create New Public IP Address
#New-AzPublicIpAddress -Name RPAPublicIP -ResourceGroupName $ResourceGroupName -AllocationMethod Dynamic -Location centralus
$vnet = Get-AzVirtualNetwork -Name $VirtualNetwork -ResourceGroupName $ResourceGroupName
$subnet = Get-AzVirtualNetworkSubnetConfig -Name $SubnetName -VirtualNetwork $vnet
$nic = Get-AzNetworkInterface -Name $NicName -ResourceGroupName $ResourceGroupName

#PublicIP is in a different ResourceGroup and has static IP needed for testing.
$pip = Get-AzPublicIpAddress -Name $PublicIPName -ResourceGroupName Research
$nic | Set-AzNetworkInterfaceIpConfig -Name $ipconfigname -PublicIPAddress $pip -Subnet $subnet
$nic | Set-AzNetworkInterface


Below is an image of this automation runbook being used in the flow as part of a condition. If the resource group and the resources from the previous step were successful, then the next action in the flow will be to run a second PowerShell runbook that assigns the public IP. If the condition is not matched, a notification email will be sent to the original email requester noting a resource creation error.


Microsoft Power Automate Flows_Part3_image 1

The runbook used in the Assign IP action has one required parameter-vendor. This parameter is the same dynamic value used in the previous step. The Reply to email (v3) uses the dynamic values of Job ID and Status Details from the previous step as reference points for the requestor of the original email. If the condition is not met, the original email requestor will receive an email like the one shown below.


Microsoft Power Automate Flows_Part3_image 2


Part four in the series will cover the next action in the flow, Robotic Process Automation with WinAutomation.


Current Flow


Microsoft Power Automate Flows_Part3_image 3


Additional Reference Information:
Azure Automation:
Automation Account:
Azure PowerShell Az module:
Manage Modules in Azure Automation:
Application and service principal objects in Azure Active Directory:
Power Automate UI Flows:


Here's a review of related posts on this series:

Dan Kiraly
Senior Research Scientist | Optiv
Dan Kiraly is senior research scientist on Optiv’s R&D team. In this role he's responsible for use case development and the vetting of security products for Optiv.