Azure Automation: Assets - Credentials

Please go through the following articles to understand the basics of Azure Automation.

  1. Azure Automation – Basics
  2. Azure Automation: Author Runbook Using PowerShell - Hello World
  3. Azure Automation - Import PowerShell Runbook From Portal Gallery
  4. Azure Automation - Publish Runbook
  5. Azure Automation: Assets – Variables
  6. Azure Automation: Assets - Modules

Azure Automation supports the following type of Assets:

Assets

In this article, we will learn more about the credentials.

Asset credentials are the entities that can be used to store your username and password of the different resources. For example, you would like to install any patch in one of your VMs. For this, you need to supply your credentials of the VM to the Azure Automation account by connecting to the VM and performing the required Administrative task.

Let’s go ahead and create the credentials.

Navigate to your Azure Automation account, go to Assets blade and click “Credentials” tile, as shown below:

Credentials

You will see the list of the credentials in your Assets. Currently, I don’t have any credentials created yet. Thus, the list is empty.

Credentials
Let’s go ahead and create one by clicking on “Add a credential” icon shown in the screenshot, above:

Add a credential

For now, let’s provide some values (need not be the valid credentials) and create the credentials by clicking the “Create” button of screenshot, shown above.

Create
As per the screenshot, mentioned above, we created a new credential named “MyTestCredentials” successfully.

Let’s see how to use or refer to them in our runbooks. Navigate to any of your existing runbooks and try to edit them.

edit

edit

In the Run book editor screen, you can see our credential under the “Credentials” sub-node of the Assets Parent node as shown below:

Runbook

Now, right click “MyTestCredentials” and click on “Add to Canvas”, as shown below:
Add to Canvas
You will see something, as shown below:

code

It has added a Cmdlet named “Get-AutomationPSCredential”, which returns the credential object with the name ‘MyTestCredentials’.

Let’s now see, how to use the username and password of the “MyTestCredentials”. In the real-world scenarios (which we will discuss in our future articles), we will use these credentials to connect to any of the Azure Services or the external resources.

If you are familiar with PowerShell, you might be aware that the PowerShell Cmdlets returns you the objects. Let’s store the output of the ‘Get-AutomationPSCredential’ Cmdlet into a variable called $MyCred,

Write-Output "Hello World"
$MyCred=Get-AutomationPSCredential -Name 'MyTestCredentials'
Write-Output 'My Username is - ' $MyCred.Username
Write-Output 'My Password is - ' $MyCred.Password

Noe, click “Test Pane” to test the code, as shown below:

Test Pane

You will be taken to the Test blade, as shown below:

Test
In the step, mentioned above, click “Start” to submit the run book for its execution.

Start

After a few seconds, you will see the output as shown below.

You can view the username that you have submitted but not the password, as it is a secured string. It will be stored in a secured way and it is nowhere displayed in any location.

Hope you enjoyed the article. Your feedback is highly appreciated.


Similar Articles