Advertisements

Creating Runbooks in Azure and Calling Them from SharePoint Using Webhooks and Flow

AzureFlowSharePointAutomationRunbooks are a feature of Azure Automation that allow you to execute workflows from within Azure or remotely to automate processes.

To give an example, lets say you have a script that monitors an Azure service every 5 minutes to see if it is running or not. The script, will test and see the status of an Azure App Service. If it tests the site, and does not get the HTTP 200/OK message, then it triggers an alert, creates a ticket, and now someone has to go recycle the Azure App Service. If this can happen frequently, then it is something you would look to automate.

In comes the Azure Automation Runbook. You create a PowerShell script that is hosted in Azure (a Runbook), and when your script detects that the service is not responding, it makes a call out to a URL, and the URL runs the Runbook, which restarts the Azure App Service. The monitoring script then runs again, sees that the service is back up, and the appropriate steps are taken.

This might seem like a lot of extra work, but, if you are, say, connecting in through a VPN to manage an Azure environment, it can be quite time consuming just to restart a service.

However, we are not using that as our working example in this article. That was just to give you an idea of the kinds of things that can be done using Runbooks. In this article, we will be showing you how to create a Runbook, and call it from SharePoint, using Microsoft Flow. It will not be a real exciting example either, but, it will show you how to do all this, so you can do more on your own!

Prerequisites

This article assumes the following:

  • You have an Azure subscription. If you do not, you can get one here for free to play around
  • You have SharePoint Online

Creating an Azure Automation Account

Before we can create our Runbook, we need to create an Azure Automation Account. Login into the Azure Portal, click on New > Monitoring + Management > Automation

image

Configure the following settings for your Automation Account:

  • Name: What are you going to call it?
  • Subscription: Select the subscription to use
  • Resource Group: Either create a new one, or, use an existing.
  • Location: Which Azure region should this run in? I am using East US 2… since I’m in the East US.
  • Create Azure Run As account: This is not needed for our test, but, if you’re doing anything in Azure with your runbooks, you will want to configure this. For more information, visit: https://docs.microsoft.com/en-us/azure/automation/automation-offering-get-started#authentication-planning

image

Then press Create.

It’ll take a moment while this deploys…

image

Once done… access it either by the Automation Accounts blade on the left side, or, via the Notifications link Go to resource once its done deploying.

image

And you will be brought to the landing page for your Automation Account, AutomationTest

image

Creating an Azure Automation Runbook

Now that we have our Automation Account, we need to create our runbook. From within the Automation Account, click on Runbooks under Process Automation on the left hand side.

image

Then click Add a runbook at the top of the runbooks dashboard

image

Click on Quick Create / Create a new runbook

image

Fill in the details

  • Name: Check-Website
    Give your runbook a name
  • Type: PowerShell
    You can also choose Python 2, Graphical, PowerShell Workflow, and Graphical PowerShell Workflow
  • Description: Check the status of a website
    Enter in a description for the runbook

Then click on Create

image

And viola! Your runbook has been created!

image

It doesn’t do anything yet, so, we will need to add code. Click on Edit at the top of the dashboard.

Here is where we will type out, or paste in our PowerShell code for the runbook.

image

NOTE: Do not use Write-Host, there is no “host” per-say to write to. Instead, ensure all output is written using Write-Output

Let’s add the following code to test if Google is up and running…

Function OutputStatus($type,$status) {
    Write-Output "$type | $status";
}

Function Get-HTTPSStatus($url,$type) {
    $HTTPSStatus = Invoke-WebRequest $url -Method Get –UseBasicParsing
    if ($HTTPSStatus.StatusCode -eq "200") {
        return OutputStatus -type $type -status "Success"
    } else {
        return OutputStatus -type $type -status "Error"
    }
}

Get-HTTPSStatus "http://www.google.com" "Google Website"

image

Click on Save

image

Now lets test it…click on Test pane

image

Click on Start

image

You will see a message that it is being submitted

image

You can then see that it gets queued

image

And finally, we see the status and the output displayed

image

Pretty neat!

Now, lets say we want to add some parameters to our script, so we can specify the input… and not have it statically set as just “http://www.google.com” as the site, and “Google Website” as the description. Let’s update the code with some parameters…

To get back to your code, click on Edit PowerShell Runbook in the breadcrumb navigation at the top

image

Update our code with the parameters $Site and $Description, and then Save, and then go back on over to the Test pane

image

You can now see we have two fields for Site and Description under Parameters. Fill those out…

image

And run the script again…

image

Looks good! Now… we can do this all day from within Azure… but remember way back to the start of this article, I mentioned calling this from Microsoft Flow from within SharePoint? To do that… we’re going to need to make a change to our script, as well as create a webhook.

First, lets change our script. You know how we just added parameters? Well, when calling a webhook, we’re going to be making a REST call to a URL. We cannot pass in parameters like we just did to the script. That is good for running within Azure itself… in order to pass parameters to our runbook via a webhook… we need to change the parameters. We will be passing in an object called WebhookData (or whatever else you want to call it). Which will be the JSON data sent along with the REST call. So, let’s update our code to this:

image

We will then parse out the Site and Description name/value pairs from that and pass it into our script from the $WebhookData object.

The code for the above is here:

Param (
    [object]$WebhookData
)

Function OutputStatus($type,$status) {
    Write-Output "$type | $status";
}

function Get-HTTPStatus($url,$type) {
    $HTTPStatus = Invoke-WebRequest $url -Method Get –UseBasicParsing
    if ($HTTPStatus.StatusCode -eq "200") {
        return OutputStatus -type $type -status "Success"
    } else {
        return OutputStatus -type $type -status "Error"
    }
}

if ($WebhookData -ne $null) {
    Get-HTTPStatus $WebhookData.RequestHeader.Site $WebhookData.RequestHeader.Description
} else {
    Write-Error "No data received in webhook call."
}

We need to Publish it first before creating the webhook. Go back to the code view, and click on Publish

image

It will prompt you to confirm, click Yes, and it’ll be published.

image

Now that we’ve got that straightened out… let’s move on to creating our webhook.

Creating a Runbook Webhook

From our runbook Dashboard, click on Webhook at the top of the dashboard

image

Click on Webhook – Create a new webhook

image

Then give it a name, and an expiration date, and if it should be enabled or not…

image

Now… notice the big warning sign at the top of this screen…

image

See? Now… copy and paste that URL at the bottom, and save it somewhere. There is no way to get this URL once the webhook has been created.

image

Once you have done that, click OK

Then click on Parameters and run settings and then click OK there

image

Then click Create at the bottom of the form. Until you do that, you can still get the webhook URL…

Ok… now what? Let’s call it from PowerShell, since we need to do a POST to access it.

image

We can see in the Content section of the output, we are given a JobId of 4164eb1f-57ba-41c3-a7cb-2f556652e9ad

In our runbook, if we go to Jobs under Resources

image

We can see that a job successfully ran

image

Click on it, and we can see the status, and you will see the JobId matches what we got from the call from Invoke-WebRequest

image

You will see there were errors… because we didn’t actually send any data along with it. We just called it directly. But now that we have it… we can move on to SharePoint and Flow.

Creating a Flow to Call our Webhook from SharePoint

Now that we’ve gone through the meat an potatoes of this project… let’s look at linking at all together with SharePoint and Flow.

Log into your SharePoint Online tenant… and lets create a new list.

I’ve got a basic custom list called Flowtest

image

Now… once created, in the Modern interface… click on Flow > Create a flow

image

Click on See your flows at the bottom, because we’re going to create a brandy-new one…

image

Click on + Create from blank at the top of the page

image

Click on Search at the bottom of the next screen, and search for SharePoint created… we want to add a trigger for when a new item is created in our list.

image

Select SharePoint – When an item is created

Select your SharePoint Online site from the list, or, enter in the URL, then select the list… in this case, we’re using Flowtest

image

Then click + New step > Add an action

image

Click on HTTP under Connectors

image

Choose HTTP – HTTP

image

Then fill out the details…

  • Method: POST
  • Uri: The URL we copied when we created our webhook
  • Headers
    Site:
    http://www.google.com
    Description: Google’s Website (FROM SHAREPOINT!)

image

And then click on Save Flow

Also… don’t forget to give your flow a name Smile

image

You should now see your Flow

image

Now… open a new window, and go back to your list, and create a new item…

image

And if you check back on your flows…

image

You will see one succeeded!

Clicking on it will give you the breakdown of the flow run (which is one of the more awesome features of Flow… over IFTTT IMHO FWIW YK?)

image

Now… let’s go check Azure…

If we look at the jobs for our Runbook… we’ll see a new one in there…

image

Click on it, and then click on the output

image

image

It worked!

Now… let’s make this a bit more functional. Go back to your list settings in SharePoint

image

I’ve changed the Title field to URL, and added a field called Description as a single line of text.

image

Now, let’s go back to our Flow…

And edit the HTTP step

image

Edit the values for Site and Description, and then select the corresponding Site and Description values from the Dynamic Content list that pops up to the right. See what we’re doing here?

image

Let’s run our Flow… create a new list item, passing in a URL and Description…

image

and check the status…

image

It worked! It’s a day of miracles people! While this is not a really exciting example, it shows how to use Azure Runbooks and Webhooks, and how they can be accessed remotely to do a specific task.

What sort of cool things are you doing or have you done with Flow and Runbooks, if anything?

Resources and References

Advertisements

Connecting to SharePoint Online using the PnP PowerShell Library and NOT Having to Log In Every. Single. Time…

imageBefore you can do anything with the SharePoint Patterns & Practices PowerShell library, you need to first connect to SharePoint Online. Sounds pretty basic, right? You need to establish who you are, and maintain your access during your session with the site you are working with.

Now, the Documentation does show you how to do this:

image

Connect-PnPOnline –Url https://geoff365.sharepoint.com –Credentials (Get-Credential)

When you do this… you are prompted for credentials… Every. Single. Time.

image

This is good for production, however, if you are developing a script, you may run this tens or hundreds of times… and, it gets old pretty fast. So, here is what I do. In my script, I set variables for the username and password (alternatively, you could pass these as parameters, and pass them along using a batch file).

image

Then, I convert the password into a secure string, and create a PSCredential object with the username and secure password.

image

I can then connect to SharePoint Online using the Connect-PnPOnline command (as shown above), wrapped in a try/catch block, and not be prompted for credentials!

image

Here’s the full script:

#region Imports
Import-Module SharePointPnPPowerShellOnline -WarningAction SilentlyContinue
#endregion Imports

#region Variables
$Username = "admin@geoff365.onmicrosoft.com"
$Password = "ThisIsNotMyRealPassword!"
$SiteCollection = "https://geoff365.sharepoint.com/sites/powershellplayground"
#endregion Variables

#region Credentials
[SecureString]$SecurePass = ConvertTo-SecureString $Password -AsPlainText -Force
[System.Management.Automation.PSCredential]$PSCredentials = New-Object System.Management.Automation.PSCredential($Username, $SecurePass)
#endregion Credentials

#region ConnectPnPOnline
try {
    Connect-PnPOnline -Url $SiteCollection -Credentials $PSCredentials
    if (-not (Get-PnPContext)) {
        Write-Host "Error connecting to SharePoint Online, unable to establish context" -foregroundcolor black -backgroundcolor Red
        return
    }
} catch {
    Write-Host "Error connecting to SharePoint Online: $_.Exception.Message" -foregroundcolor black -backgroundcolor Red
    return
}
#endregion ConnectPnPOnline

May 2014 #CollabTalk TweetJam On Hybrid SharePoint

Reposted from: http://www.buckleyplanet.com/2014/05/may-2014-collabtalk-tweetjam-on-hybrid-sharepoint.html

As organizations look to the future of their existing SharePoint environments, questions about hybrid deployments come up again and again. For this month’s #CollabTalk tweetjam, scheduled for May 29th at 9am Pacific / 12pm Eastern we have an all-start panel of experts who will be tackling this topic, CollabTalk May 2014answering questions, and sharing their real-life experiences. Our theme will be “What It Takes to Get Hybrid SharePoint Right,” and we want your questions and feedback during this one-hour online event.

As organizations begin to seriously consider the future of their existing SharePoint infrastructure, some are moving directly to the cloud and Office365, while others are looking to extend their infrastructure investments, protect sensitive data, and/or maintain the level of control they have over line of business (LOB) integrations and other customizations. The long-and-short of it is that hybrid SharePoint deployments will be around for some time, and Microsoft will continue to support on premises deployments for the foreseeable future. In this month’s tweetjam panel, we’ll talk about the business reasoning behind the decisions to go hybrid, while also shedding some light on the roadblocks and realities of keeping one foot on prem and the other foot in the cloud.

If you’re new to the tweetjam model, basically its an hour-long public conversation held on Twitter and using a shared hash tag, which is #CollabTalk. You can use your Twitter platform of choice OR go over to http://twubs.com/CollabTalk which automatically appends each message with #CollabTalk, and has a nice feature that allows followers to actually slow the dialog down to a readable speed (it can fly by fairly quickly). The questions we will be discussing are listed below:

"What It Takes to Get Hybrid SharePoint Right"

  • As companies transition toward the cloud, how important will hybrid become?
  • What are the most common hybrid SharePoint scenarios?
  • How much of hybrid SharePoint is platform versus services?
  • Is a hybrid search deployment difficult, and if so, what are the pain points?
  • What are the top 3 road blocks for adopting a hybrid SharePoint model?
  • What features/solutions should Microsoft focus on to improve hybrid deployments?
  • What advice would you give to an admin considering a hybrid SharePoint environment?

As always, we will have an extensive all-star panel of experts on hand to participate in the conversation and to interact with you directly – but anyone can jump in and participate. So don’t be shy — share your own perspective and company or customer experiences, or just lurk. It’s all good. But be sure to mark your calendars, tell your colleagues, and get involved!

Our panel this month will include:

  • Dave Coleman (@dcoleman146), SharePoint MVP and director at SharePointEduTech
  • Ben Curry (@curryben), SharePoint MVP, principal architect and managing partner at Summit 7 Systems
  • Bradley Geldenhuys (@bradgcoza), SharePoint Jedi at GTConsult
  • Asif Rehmani (@asifrehmani), consultant, trainer and SharePoint MVP at SharePoint-Videos
  • Tamir Orbach (@tamirorbach), director of product management at Metalogix
  • Naomi Moneypenny (@nmoneypenny), cto at ManyWorlds
  • Dan Holme (@danholme), SharePoint MVP, evangelist, and co-founder of ITUnity
  • Jeffrey Schwartz (@jeffreyschwartz), editor of Redmond Magazine and editor-at-large for Redmond Channel Partner magazine
  • Edin Kapic (@ekapic), SharePoint MVP and architect at Spenta
  • Adis Jugo (@adisjugo), SharePoint MVP, Top 25 SharePoint Influencer 😛 and head of development at deroso Solutions
  • Dan Usher (@binarybrewery), SharePoint MVP, implementation engineer and architect at Booz Allen Hamilton
  • Kanwal Khipple (@kkhipple), SharePoint MVP and director of digital strategy at Envision IT
  • Hans Brender (@hansbrender), SharePoint MVP and ceo of sqtm PSC GmbH
  • Robert Bogue (@robbogue), SharePoint MVP, author and consultant
  • Juan Carlos Gonzalez Martin (@jcgm1978), SharePoint MVP, co-director of the magazine CompartiMOSS, consultant and solution architect at LKS
  • Ivan Sanders (@iasanders), SharePoint MVP, developer and consultant
  • Adam Preston (@_apreston), manager of collaboration and cloud services at TCSC, and president of the Richmond SharePoint Users Group
  • Jason Ruthkoski (@jasonruthkoski), team lead, portals and collaboration at Slalom Consulting
  • Eric Riz (@rizinsights), evp at Concatenate and SharePoint MVP
  • Jeff Fried (@jefffried), cto and vp of engineering at BA Insight
  • Jennifer Mason (@jennifermason), SharePoint MVP and consultant at Rackspace
  • Geoff Varosky (@gvaro), managing consultant at Jornata, president of Boston Area SharePoint Group, and co-founder of Boston Office365 User Group
  • Fabian Williams (@fabianwilliams), SharePoint MVP and senior consultant at Planet Technologies
  • Michael Herman (@mwherman2000), principal architect at Parallelspace
  • Laura Rogers (@wonderlaura),  SharePoint MVP and consultant at Rackspace
  • Jared Shockley (@jshoq), senior systems engineer at Microsoft
  • Alistair Pugin (@alistairpugin), SharePoint MVP and independent consultant
  • Chris Beckett (@teknirvana), founder of obeflow and SharePoint MCM
  • Richard Harbridge (@rharbridge), partner technology advisor and strategist at Microsoft
  • Paul Swider (@pswider), cto at RealActivity and enterprise SharePoint strategist
  • Todd Klindt (@toddklindt), SharePoint MVP and consultant at Rackspace
  • Thomas Carpe (@thomascarpe), principal SharePoint architect at Liquid Mercury Solutions
  • Robert Toro (@SharePointToro), SharePoint practice director at Slalom
  • Warren Marks (@MarksWazza), director at GTconsult
  • and myself as your host and moderator (@buckleyplanet), SharePoint MVP and chief evangelist at Metalogix

I am excited to once again have a lively debate, and look forward to the interaction on #CollabTalk. My plan is to provide a summary of the discussion on the ITUnity.com site within the next few days, so watch for an update via my Twitter, Facebook and LinkedIn updates. See you online this Thursday at Twubs.com/CollabTalk

Boston Office 365 Group Launch

BosO365-UG-Logo-650x225

Are you curious about Office 365? What it is, how it can save you time and help you be more productive? Are you getting the full benefits of all that Office 365 has to offer?

One of the ways for people to get the most out of this new and constantly evolving suite of products is to have people to turn to; a place to go to explore new features and functionality or just learn more, share experiences and ask questions. Formal training is great (we strongly encourage ongoing training for users of the Office 365 suite of products), but there are times when you just want to interact with others or ask a simple question.

Help has arrived. Jornata is pleased to be a founding organizer of the Boston Office 365 User Group. Our co-organizers include Microsoft, Wellington Street Consulting, Slalom Consulting and Cognizant Technology Solutions. The group will met monthly, beginning on Thursday, May 22nd, and on the third Thursday of every month thereafter. The event will take place at Microsoft’s New England Research and Development Center (NERD) at One Memorial Drive in Cambridge. Attendance is free and food and beverages will be provided. You can learn more and register for the meeting or join the mailing list.

Fittingly, for the initial event, Microsoft’s Chris Bortlik will present an overview of Office 365. His discussion will include an overview of current Office 365 functionality, including Yammer, Lync Online, mobile applications and Office 365 Pro Plus. He’ll also explore administration and update issues. Chris is an Office 365 technology architect at Microsoft.

There are plenty of ways to keep the conversation going. We have a web site, Linked In group and Yammer group, or you can follow us on Twitter @Bos365.

We want this to be your group. Feedback, ideas, and suggestions are welcome. What topics would you like to see the group address? Are there other elements that you feel should be added to the program? We’ll provide a place to air your grievances and perhaps learn how others have dealt with the issues you’ve encountered.

We’re also looking for event sponsors to provide food, beverages and raffle prizes for the events or pick up the tab for the Office 365 Happy Hour that will follow each meeting at a local bar or restaurant. If you’re interested, or know anyone who might be, please contact us.

We look forward to seeing you there!

Creating a Licensed Users View in Office 365

In Office 365, when managing users and groups under the Office 365 Admin Center, they have several canned views you can use to filter the list of employees and groups that you see.

image

One which is not there by default, which is a custom view, is Licensed Users. You can easily create views or edit existing views by using the menu items at the bottom. In this case, we are going to create a New view

image

First, just like any other view in SharePoint, you need to give the view a name. In this case, I used Licensed Users

image

I’ve left every other option blank except for Assigned license. I’ve changed this field to reflect my client’s license plan, which is the E3 license.

image

Click Save, and you’re good to go.

If you have multiple licenses in use, you will need to create multiple views, as it is a single selection drop-down.

I have a Public SharePoint Online site?

Yes. Yes you do. Well, if you have Office 365 and it is part of the license which you purchased. You didn’t have to do anything, you have a public facing (anyone on the internet can hit it just like a normal website) website.

Where is it?

It’s easy to find. Go into the SharePoint Online Admin Center

image

Select the first link on the left side navigation (the default) site collections

image

And in the listing on the right side of the page, it will be listed first under Public Website

image

The default URL will be http://yourtenantname-public.sharepoint.com.

And if you go there…You’ll see a nice SharePointy and Cloudy site…

image

 

Oh Cool! Now I can create a website like Ferrari in Office 365/SharePoint Online????

No. As of yet, SharePoint Online in Office 365 does not contain all of the super awesome Web Content Management and publishing controls that SharePoint 20XX on-premises does.

Oh…

Yep.

Ok, the public website is enough for my needs, can I create more than one?

No. Once you have one created, you cannot create another one. It will appear greyed out when attempting to create a new site collection.

image

Oh…

Yep.

Enabling Office on Demand in SharePoint Online

Office on Demand is a new feature in SharePoint Online on Office 365. Straight from the link, from the horses’ mouth so to speak:

Office on Demand is a feature that provides online access to full rich Office desktop applications, including Word, Excel, and PowerPoint, when you’re using a PC that doesn’t have the latest version of Office installed locally. Office on Demand is available to anyone who has an Office 365 subscription that includes the Office application suite. Office 365 subscriptions that include the Office applications let you install on up to five devices for use both online and offline. Office on Demand is a helpful option if you want to use your Office applications on an additional device or on a device that you don’t own, such as when you’re logged in as a guest using someone else’s computer.

This also works in environments where thin clients are used such as a Citrix or kiosk based setup where users cannot install software, and license management can become quite the hassle if multiple users are using the same server to do their work each day.

To enable or disable Office on Demand

Go into your SharePoint Online Admin Center

image

and select Settings from the left-side navigation

image

And then scroll down to the Office on Demand header to enable or disable the functionality.

image

Managing External Sharing in SharePoint Online

A question I frequently hear from clients when moving to Office 365 and SharePoint online, is how can I manage external sharing?

Maybe an organization does not want to allow content to be shared with external users, or allow users direct access to documents without first having an account and logging in. There are many different situations and requirements which may need to have the external sharing settings tweaked.

To do so, go into your SharePoint Online Admin Center

image

and select Settings from the left-side navigation

image

And then once there (and currently it is the second header down on the right side of the screen), choose one of the options which firs your requirements.

  • Don’t allow sharing outside your organization
  • Allow external users who accept sharing invitations and sign in as authenticated users
  • Allow both external users who accept sharing invitations and anonymous guest links

image

SharePoint Online is…Helpful!

In many cases when working with SharePoint, you do not always know “what happens next” when do perform an operation in SharePoint. Microsoft is working to change that, especially with SharePoint Online and Office 365. Now, when performing actions, things have been re-worded, or additional information and confirmations have been added to the screens, since it is not just us SharePoint nerds managing deployments anymore with SharePoint Online.

Example: Deleting a Site Collection

image

See what they did there? Big red letters, stating that you can no longer access SharePoint anymore if you delete the root/main site collection in SharePoint online. It’s not wordy, and its in RED. You should hopefully not gloss over it. This will hopefully save some headaches and confusion.

How Do I Upgrade My Trial Office 365 Subscription to a Subscription Plan?

It is very cool, you get a 90 day trial for Office 365 to really test out the system and see what works, what doesn’t, and plan for your move to the service. 90 days, and you can even ask for extensions to make sure that this is the right solution for you. Not many services offer that even by a long shot. Microsoft wants you to make the right decision.

So, now that you’ve decided to go with Office 365, how can you keep all of your work and get properly licensed? It’s quite simple. Go to the Office 365 Admin Center

image

Select Purchase Services from the left-side navigation

image

You will see your current plan, listed as Currently in trial

image

Click the handy Buy now link…

image

And complete the process from there.

HOWEVER….. make sure you have your licensing trued up first. If you have licensed all 250 trial users you can have, and you only need 30… that first bill is going to be awfully painful.

%d bloggers like this: