Have you tried making a ‘simple’ script to monitor directory and when new content arrives move that to another location or do simple transformations on the filename? I have tried and frustrated. You must think of scheduling, manipulation logic and error handling.

Logic Apps is an Integration platform that an IT Pro can very easily learn to use and make their life much easier. Azure has multiple solutions that can be used to archive the same end result – the path to the goal differs between tools. Azure Automation, Azure Functions, Azure Logic Apps (and Microsoft Flow) are all tools that you can automate your life with. I will now discuss Logic Apps and the problem specified above. The rest of the tools will be introduced here in the future.

It takes no more than 30 minutes to build a solution for the introduced problem from the scratch. This sample solution monitors directory for new files in set intervals and when new files arrive, it moves the files to another file share on another computer (and you can use different credentials very easily).

Recipe

Ingredients

Preparations

Install Data Gateway to a server in your network. It doesn’t need to be on the server that is hosting the directory you want to monitor. Installer asks for your Azure credentials to register the gateway to Azure. Specify the same region that your are normally using. There are some limitations on regions but using West Europe everything works fine. Firewall-wise Data Gateway needs only outbound internet connection.
Connect Data Gateway to Azure by creating On-premises data gateway connection from Marketplace. After this you are set to create the actual magic.

Create new Logic App from Marketplace. Name your application according to your governance document and naming standard. I prefer to use prefix “la-” for Logic Apps.

You can connect Logic App to Log Analytics for centralized dashboard for all your Logic Apps.

Creating new Logic App from Marketplace

Start defining your logic. In this case we use blank template, but there are lots of ready templates to be used as they are or they can be adapted for your specific needs.

There are many templates available

Use File System Connector and “When a file is created (properties only)” as a trigger of the logic.

Selecting correct trigger

Create a new connection. Here you specify the root path that the connection is allowed to use. Later you specify what to do with this connection. Select the previously created On-premises Gateway from the gateway drop down list. Here I use “euw-espautom01”.
Note that the username for access MUST BE in legacy format eg. DOMAIN\svc-logicApp

Creating new File System connection

Building the Logic App

Build the flow. You can use the built-in directory browser to set the directory that you want to monitor.
Specify how often you want to monitor the new files added. Note that Logic App is billed per actions and a trigger check is also an action. The per action cost is very small but if the trigger is checking very frequently costs might surprise you.

Browsing the monitored file system

Add Get Content and Create File actions. Logic is that when a new file is detected, its content is read and with that content a new file is created. In this sample we create a new file with the same name but using different connection. The UI is very intuitive. Data from previous steps is available for next actions. Get Content action uses List of Files Path from trigger action and Create File uses Content from Get File Content and File Name from trigger.

Dynamic content addition
Whole Logic App with all the steps

Logic App is now ready and you can test it by copying something to a monitored folder. After specified time, Logic App is fired and file copied to target folder.
Runs are shown in the monitor view and you can setup alerts to notify you if the run fails.

Logic App Monitoring

Extending the solution

There are connectors to OneDrive, SharePoint, Google Drive, Dropbox and dozens of more. You can easily transfer files from on-premises file share to Azure Blob if that is your use case. You could even extract the content of the file and post that to Teams channel. The possibilities are endless and logic is very easy to implement.

I am using this to automate simple or more complex workflows that previously could take hours to code in PowerShell. Logic App is the tool for thinking outside the box and making your life much easier.


Mika Vilpo

I started my current employment as an Identity and Access Management Consultant building challenging automated solutions and have recently shifted more to public cloud as there the future of identity and automation lies. I have seen Office 365 evolve from Live@Edu to current strengths and love to see how to story evolves. Currently I am building customers' architecture and solutions based on Microsoft Azure PaaS and IaaS.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.