Geoff Varosky's Blog

SharePoint, Office 365, Azure, and Other Musings…

  • Home
  • About
  • Blog Links
  • Calendar
Posts Comments
  • SharePoint
  • SharePoint 2010
  • Events
    • SharePoint Saturday
    • User Groups
      • BASPUG
  • Office 365
  • PowerShell
  • SharePoint Online
  • SharePoint 2013

Azure Automation Credentials

February 23, 2018 Leave a comment

imageI have been playing around with Azure Automation Runbooks as of late. For one I was working on, I am using a SharePoint list to kick off a flow, and that flow reaches out to my Azure Runbook via a Webhook, which in turns runs some PowerShell using the SharePoint PnP Library to create some list entries, as well as a site or two, depending on the request.

Since I have just been testing this functionality out, I’ve had my credentials under which the script runs and connects to SharePoint under a few variables.

$username = "geoff@domain.com"
$password = "!!!MySuperSecurePassword!!!~)()_($!@)(&$_)*($&@)*"

And then converting those to PowerShell credentials

[SecureString]$securePass = ConvertTo-SecureString $password -AsPlainText -Force
[System.Management.Automation.PSCredential]$psCredentials = New-Object System.Management.Automation.PSCredential($username, $securePass)

And then connecting to SharePoint

Connect-PnPOnline -Url $url -Credentials $psCredentials -ErrorAction Stop

Now that I have my testing near completed, I no longer wanted to store my username and password for my service account in the script itself as variables. In fact, I want to be able to use multiple credential sets if needed, depending on the tasks that need to be completed. In comes Azure Automation Credentials.

Creating Azure Automation Credentials

I’ll skip the step of creating an Azure Automation account, I covered that in my last post related to this. Since the

If you go into the Azure Portal, and go into your Azure Automation account, you will see under Shared Resources, a section called Credentials

image

Click on Add a credential

image

Enter in a Name, Description, and then the User name and Password for the credentials you wish to use.

image

And then click on Create

image

Using Azure Automation Credentials

Now that we’ve created our credentials… we can use them! In this example, I am just using a test script to ensure it works…Let’s go over to our runbook.

image

You can see here in my example script, that instead of the code I used above, I am using:

Get-AutomationPSCredential -Name "MyAccount"

Where MyAccount is the name of the credential we just configured. Let’s now go test it out… go over to the Test Pane and click on Start

I am showing some output just to confirm that the script is indeed running, and it is getting PS Credentials, etc.

And did we get context?

image

Indeed we did! It works! I surprise myself sometimes… so there you go, this is how you can use Azure Automation Accounts and Automation Credentials to store and retrieve username and password pairs and use them in your Automation Runbooks.

References

  • Credential assets in Azure Automation
  • SharePoint Patterns and Practices (PnP) PowerShell Library

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on X (Opens in new window) X
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to email a link to a friend (Opens in new window) Email
  • Click to print (Opens in new window) Print
Like Loading...

Filed under Azure, Azure Automation, PowerShell, SharePoint, SharePoint Online Tagged with Azure, Azure Automation, azure automation account, azure runbook, azure webhook, azurerm, Patterns & Practices, Patterns and Practices, pnp, runbook, runbook webook, runbooks, SharePoint, sharepoint patterns & practices, sharepoint patterns and practices, sharepoint pnp, webhook

Categories

Archives

Top Posts

  • SharePoint Site Collection backup failed–site left locked.
  • System.UnauthorizedAccessException: Filename: redirection.config
  • SharePoint 2016 Web Template List
  • Upgrading to an Enterprise License in SharePoint 20XX
  • Creating an Azure Run As Account

Twitter Feed (@gvaro)

Tweets by gvaro

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 87 other subscribers
All content copyright 2007-2017 Geoff Varosky. All rights reserved.

Blog at WordPress.com.

  • Subscribe Subscribed
    • Geoff Varosky's Blog
    • Join 87 other subscribers
    • Already have a WordPress.com account? Log in now.
    • Geoff Varosky's Blog
    • Subscribe Subscribed
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
%d