Listen – creating resources in Azure with PowerShell is easy – but actually knows what you have deployed is something else. Let’s dive into the steps to harness the power of PowerShell for a streamlined Azure inventory process.
Prerequisites
Before we embark on this journey, ensure you have:
An Azure account with necessary access permissions.
PowerShell and the Azure PowerShell module ready on your machine.
Configuring PowerShell for Azure
Connecting to Azure is the first step. Open your PowerShell window and enter these commands. This should let you set your context from the Gridview.
# Connect to Azure with interactive login
Connect-AzAccount
# List subscriptions and select one interactively
Get-AzSubscription | Out-GridView -PassThru | Set-AzContext
Lets go ahead and start to look at your resources:
# List all resources and export to CSV
Get-AzResource | Select-Object ResourceType, Name, Location | Export-Csv -Path ./AllResources.csv -NoTypeInformation
# VM Inventory: List VMs and export their details
Get-AzVM | Select-Object Name, Location, HardwareProfile.VmSize | Export-Csv -Path ./VMInventory.csv -NoTypeInformation
# Storage Accounts: List accounts and export their details
Get-AzStorageAccount | Select-Object StorageAccountName, Location, SkuName | Export-Csv -Path ./StorageAccounts.csv -NoTypeInformation
# Network Resources: List VNets and export their details
Get-AzVirtualNetwork | Select-Object Name, Location, AddressSpace | Export-Csv -Path ./VNetInventory.csv -NoTypeInformation
In the scripts above, each command not only fetches the necessary details but also exports them to a CSV file for easy access and reporting.
Advanced Techniques
Organizing and managing your resources effectively can further be achieved by using tags.
# Organizing resources with Tags: Filter by tag and export
Get-AzResource -Tag @{ Department="Finance"} | Select-Object Name, ResourceType | Export-Csv -Path ./FinanceResources.csv -NoTypeInformation
For more insights and advanced techniques, visit the Azure PowerShell documentation. Here’s to efficient management of your Azure resources. Happy scripting!
Alright folks – we’re going to dive into how you can leverage Azure Cognitive Services with PowerShell to not only set up AI services but also to interact with them. Let’s go!
Prerequisites
Before we begin, ensure you have the following:
An Azure subscription.
PowerShell 7.x or higher installed on your system.
Azure PowerShell module. Install it by running Install-Module -Name Az -AllowClobber in your PowerShell session.
Use Connect-AZAccount to get into your subscription, then run this to create a new RG and Cognitive Services resource:
$resourceGroupName = "<YourResourceGroupName>"
$location = "EastUS"
$cognitiveServicesName = "<YourCognitiveServicesName>"
# Create a resource group if you haven't already
New-AzResourceGroup -Name $resourceGroupName -Location $location
# Create Cognitive Services account
New-AzCognitiveServicesAccount -Name $cognitiveServicesName -ResourceGroupName $resourceGroupName -Type "CognitiveServices" -Location $location -SkuName "S0"
It’s that simple!
To interact with Cognitive Services, you’ll need the access keys. Retrieve them with:
With your Cognitive Services resource set up and your access keys in hand, you can now interact with various cognitive services. Let’s explore a couple of examples:
Text Analytics
To analyze text for sentiment, language, or key phrases, you’ll use the Text Analytics API. Here’s a basic example to detect the language of a given text:
So this code will try and determine the language of the text submitted. The output might look like this:
Name ConfidenceScore
---- ---------------
English 0.99
Let’s try computer vision now:
Computer Vision
Azure’s Computer Vision service can analyze images and extract information about visual content. Here’s how you can use PowerShell to send an image to the Computer Vision API for analysis:
Before integrating AI into your Azure automation processes, it’s crucial to assess your current Azure environment. This assessment will help identify the strengths, limitations, and potential areas for improvement.
Evaluate Existing Resources and Capabilities
Take an inventory of your current Azure resources. This includes virtual machines, databases, storage accounts, and any other services in use.
Assess the performance and scalability of these resources. Are they meeting your current needs? How might they handle increased loads with AI integration?
Use Azure’s built-in tools like Azure Advisor for recommendations on optimizing resource utilization.
Review Current Automation Configurations
Examine your existing automation scripts and workflows. How are they configured and managed? Are there opportunities for optimization or enhancement?
Consider the use of Azure Automation to streamline these processes.
Identify Data Sources and Workflows
Identify the data sources that your automation processes use. How is this data stored, accessed, and managed?
Map out the workflows that are currently automated. Understanding these workflows is crucial for integrating AI effectively.
Check Compliance and Security Measures
Ensure that your setup complies with relevant data protection regulations and security standards. This is particularly important when handling sensitive data with AI.
Pinpoint where in your current setup AI can be integrated for maximum benefit. Look for processes that are repetitive, data-intensive, or could significantly benefit from predictive insights.
After assessing your Azure environment, the next step is to set up and configure the essential services that form the backbone of AI-driven automation. Here’s how you can approach the setup of these key services:
Navigate to Machine Learning: Find “Machine Learning” under “AI + Machine Learning” in the ‘All services’ section.
Create a New Workspace: Click “Create” and choose your Azure subscription and resource group.
Configure Workspace: Provide a unique name, select a region, and optionally choose or allow Azure to create a storage account, key vault, and application insights resource.
Review and Create: Verify all details are correct, then click “Review + create” followed by “Create” to finalize.
Access the Workspace: After creation, visit your resource group, select the new workspace, and note the key details like subscription ID and resource group.
Explore Azure Machine Learning Studio: Use the provided URL to access the studio at https://ml.azure.com and familiarize yourself with its features.
Set Up Additional Resources: If not auto-created, manually set up a storage account, key vault, and application insights resource in the same region as your workspace.
Azure Cognitive Services
Navigate to Cognitive Services: Search for “Cognitive Services” in the portal’s search bar.
Create a Resource: Click “Create” to start setting up a new Cognitive Services resource.
Fill in Details: Choose your subscription, create or select an existing resource group, and name your resource.
Select the Region: Choose a region near you or your users for better performance.
Review Pricing Tiers: Select an appropriate pricing tier based on your expected usage.
Review and Create: Confirm all details are correct, then click “Review + create”, followed by “Create”.
Access Resource Keys: Once deployed, go to the resource, and find the “Keys and Endpoint” section to get your API keys and endpoint URL.
Integrate with Applications: Use the retrieved keys and endpoint to integrate cognitive services into your applications.
Azure Logic Apps
Search for Logic Apps: In the portal, find “Logic Apps” via the search bar.
Initiate Logic App Creation: Click “Add” or “Create” to start a new Logic App.
Configure Basic Settings: Select your subscription, resource group, and enter a name for your Logic App. Choose a region.
Create the Logic App: After configuring, click “Create” to deploy your Logic App.
Open Logic App Designer: Once deployed, open the Logic App and navigate to the designer.
Design the Workflow: We will go over this later! This is where the fun begins!!
Setting up these essential Azure services is a foundational step in creating an environment ready for AI-driven automation. Each service plays a specific role, and together, they provide a powerful toolkit for automating complex and intelligent workflows.
Leveraging Azure Machine Learning
Create a Machine Learning Model:
Navigate to Azure Machine Learning Studio.
Create a new experiment and select a dataset or import your own.
Choose an algorithm and train your machine learning model.
Deploy the Model:
Once your model is trained and evaluated, navigate to the “Models” section.
Select your model and click “Deploy”. Choose a deployment option (e.g., Azure Container Instance).
Configure deployment settings like name, description, and compute type.
Consume the Model:
After deployment, get the REST endpoint and primary key from the deployment details.
Use these details to integrate the model into your applications or services.
Utilizing Azure Cognitive Services
Select a Cognitive Service:
Determine which Cognitive Service (e.g., Text Analytics, Computer Vision) fits your needs.
In Azure Portal, navigate to “Cognitive Services” and create a resource for the selected service.
Configure and Retrieve Keys:
Once the resource is created, go to the “Keys and Endpoint” section.
Copy the key and endpoint URL for use in your application.
Integrate with Your Application:
Use the provided SDK or REST API to integrate the Cognitive Service into your application.
Pass the key and endpoint URL in your code to authenticate the service.
Automating with Azure Logic Apps
Create a New Logic App:
In Azure Portal, go to “Logic Apps” and create a new app.
Select your subscription, resource group, and choose a name and region for the app.
Design the Workflow:
Open the Logic App Designer.
Add a trigger (e.g., HTTP request, schedule) to start the workflow.
Add new steps by searching for connectors (e.g., Azure Functions, Machine Learning).
Integrate AI Services:
Add steps that call Azure Machine Learning models or Cognitive Services.
Configure these steps by providing necessary details like API keys, endpoints, and parameters.
Save and Test the Logic App:
Save your changes and use the “Run” button to test the Logic App.
Check the run history to verify if the workflow executed as expected.
Welcome to my new blog series on “AI-Enhanced Event Automation in Azure,” where I will delve into the integration of AI with Azure’s amazing automation capabilities. This series will be more than just a conceptual overview; it will be a practical guide to applying AI in Azure.
Through this series I will explore the role of AI in enhancing Azure’s event monitoring and automation processes. This journey will be tailored for those with a foundational understanding of Azure, aiming to leverage AI to unlock unprecedented potential in cloud computing.
We will begin with the basics of setting up your Azure environment for AI integration, where we’ll reference Azure’s comprehensive Learn documentation.
Moreover, I’ll explore advanced AI techniques and their applications in real-world scenarios, utilizing resources from the Azure AI Gallery to illustrate these concepts.
Let’s dig in!
Key Concepts and Terminologies
To ensure we’re all on the same page let’s clarify some key concepts and terminologies that will frequently appear throughout this series.
Artificial Intelligence (AI): AI involves creating computer systems that can perform tasks typically requiring human intelligence. This includes learning, decision-making, and problem-solving. Azure provides various AI tools and services, which we will explore. Learn more about AI in Azure.
Azure Automation: This refers to the process of automating the creation, deployment, and management of Azure resources. Azure Automation can streamline complex tasks and improve operational efficiencies. Azure Automation documentation offers a comprehensive guide.
Azure Logic Apps: These are part of Azure’s app service, providing a way to automate and orchestrate tasks, business processes, and workflows when you need to integrate apps, data, systems, and services across enterprises or organizations. Explore Azure Logic Apps.
Machine Learning: A subset of AI, machine learning involves training a computer system to learn from data, identify patterns, and make decisions with minimal human intervention. Azure’s machine learning services are pivotal in AI-enhanced automation. Azure Machine Learning documentation provides detailed information.
Event-Driven Architecture: This is a design pattern used in software architecture where the flow of the program is determined by events. In Azure, this concept is crucial for automating responses to specific events within your infrastructure. Understanding Event-Driven Architecture in Azure can give you more insights.
Understanding these terms will be key to concepts we will discuss in this series. They form the building blocks of our exploration into AI-enhanced automation in Azure.
The Role of AI in Azure Automation
AI is not just an add-on but a transformative resource. AI in Azure Automation opens up new avenues for efficiency, intelligence, and sophistication in automated processes.
Enhancing Efficiency and Accuracy: AI algorithms are adept at handling large volumes of data and complex decision-making processes much faster than traditional methods. In Azure, AI can be used to analyze operational data, predict trends, and automate responses with high precision. This leads to a significant increase in the efficiency and accuracy of automated tasks. AI and Efficiency in Azure provides further insights.
Predictive Analytics: One of the most significant roles of AI in Azure Automation is predictive analytics. By analyzing historical data, AI models can predict future trends and behaviors, enabling Azure services to proactively manage resources, anticipate system failures, and automatically adjust to changing demands. The Predictive Analytics in Azure guide is a valuable resource for understanding this aspect.
Intelligent Decision Making: AI enhances Azure automation by enabling systems to make smart decisions based on real-time data and learned patterns. This capability is particularly useful in scenarios where immediate and accurate decision-making is critical, such as in load balancing or threat detection. Azure’s Decision-Making Capabilities further explores this topic.
Automating Complex Workflows: With AI, Azure can automate more complex, multi-step workflows that would be too intricate or time-consuming to handle manually. This includes tasks like data extraction, transformation, loading (ETL), and sophisticated orchestration across various services and applications. Complex Workflow Automation in Azure provides a deeper dive into this functionality.
Continuous Learning and Adaptation: A unique aspect of AI in automation is its ability to continuously learn and adapt. Azure’s AI-enhanced automation systems can evolve based on new data, leading to constant improvement in performance and efficiency over time.
By integrating AI into Azure Automation, we unlock a realm where automation is not just about executing predefined tasks but about creating systems that can learn, adapt, and make intelligent decisions. This marks a significant leap from traditional automation, propelling businesses towards more dynamic and responsive operational models.
Examples of AI Enhancements in Automation
Understanding the practical impact of AI in Azure automation is easier with real-world examples.
Automated Scaling Based on Predictive Analytics: Utilizing AI for predictive analysis, Azure can dynamically adjust resources for an e-commerce platform based on traffic and shopping trends, optimizing performance and cost. Learn more about Azure Autoscale.
Intelligent Data Processing and Insights: Azure AI can analyze large datasets, like customer feedback or sales data, automating the extraction of valuable insights for quick, data-driven decision-making. Explore Azure Cognitive Services.
Proactive Threat Detection and Response: AI-driven monitoring in Azure can identify and respond to security threats in real-time, enhancing network and data protection. Read about Azure Security Center.
Custom Workflow Automation for Complex Tasks: In complex sectors like healthcare or finance, AI can automate intricate workflows, analyzing data for risk assessments or health predictions, improving accuracy and efficiency. Discover Azure Logic Apps.
Adaptive Resource Management for IoT Devices: For IoT environments, Azure’s AI automation can intelligently manage devices, predict maintenance needs, and optimize resource allocation. See Azure IoT Hub capabilities.
These examples highlight AI’s ability to revolutionize Azure automation across various applications, demonstrating efficiency, insight, and enhanced security.
Challenges and Considerations
While integrating AI into Azure automation offers numerous benefits, it also comes with its own set of challenges and considerations.
Complexity of AI Models: AI models can be complex and require a deep understanding of machine learning algorithms and data science principles. Ensuring that these models are accurately trained and tuned is crucial for their effectiveness. Understanding AI Model Complexity provides more insights.
Data Privacy and Security: When dealing with AI, especially in automation, you often handle sensitive data. Ensuring data privacy and complying with regulations like GDPR is paramount. Azure’s Data Privacy Guide offers guidelines on this aspect.
Integration and Compatibility Issues: Integrating AI into existing automation processes might involve compatibility challenges with current systems and workflows. Careful planning and testing are essential to ensure seamless integration. Azure Integration Services can help understand these complexities.
Scalability and Resource Management: As your AI-driven automation scales, managing resources efficiently becomes critical. Balancing performance and cost, especially in cloud environments, requires continuous monitoring and adjustment. Azure Scalability Best Practices provides valuable insights.
Keeping up with Technological Advancements: The field of AI is rapidly evolving. Staying updated with the latest advancements and understanding how they can be applied to Azure automation is crucial for maintaining an edge. Azure Updates is a useful resource for keeping up with new developments.
By understanding and addressing these challenges, you can more effectively harness the power of AI in Azure automation, leading to more robust and efficient solutions.
That’s all for now! In the next post we will dig into Azure and actually start to get our hands dirty!
Setting up solar on our farm in North Texas has been a treasure trove of data to analyze – everything from Inverter load, to PV watts in, to state-of-charge for the batteries – It’s a massive amount of useful information.
So naturally I want that data in Azure Log Analytics. It’s perfect platform to handle this amount of data. Small messages, lots of entries. Just ready for reporting and analytics.
To do this, we are going to use IOT Hub as a go-between. Here are the high-level steps:
To get MQTT data into Azure Log Analytics via IoT Hub, you will need to perform the following steps:
Set up an IoT hub in your Azure account.
Set up a device in your IoT hub.
Configure the device to send data to your IoT hub using the MQTT protocol.
Set up a log analytics workspace in your Azure account.
Connect your IoT hub to your log analytics workspace.
Start sending MQTT data from your device to your IoT hub.
And now some details:
Set up an IoT hub in your Azure account:
In the Azure portal, click on “Create a resource” in the top left corner, then search for “IoT Hub” and select it.
Follow the prompts to create a new IoT hub, including selecting the subscription, resource group, and region you want to use.
Make note of the IoT hub’s name and connection string, as you will need these later.
Set up a device in your IoT hub:
In the Azure portal, go to the IoT hub blade and select “IoT Devices” from the left menu.
Click the “Add” button to create a new device.
Follow the prompts to set up the device, including giving it a unique device ID and generating a device key or certificate.
Make note of the device ID and key/certificate, as you will need these later.
Configure the device to send data to your IoT hub using MQTT:
The specific steps for this will depend on the device you are using, but generally you will need to specify the MQTT endpoint and authentication information for your IoT hub.
The MQTT endpoint will be in the format “YOUR-IOT-HUB-NAME.azure-devices.net”, and you will need to use the device ID and key/certificate you obtained in step 2 to authenticate.
Specify the MQTT topic you want to publish data to.
Set up a log analytics workspace:
In the Azure portal, click on “Create a resource” in the top left corner, then search for “Log Analytics” and select it.
Follow the prompts to create a new log analytics workspace, including selecting the subscription, resource group, and region you want to use.
Make note of the workspace ID and primary key, as you will need these later.
Connect your IoT hub to your log analytics workspace:
In the Azure portal, go to the IoT hub blade and select “Diagnostic settings” from the left menu.
Click the “Add diagnostic setting” button to create a new setting.
Select the log analytics workspace you created in step 4 as the destination for the data.
Select the data types you want to collect
Start sending MQTT data from your device to your IoT hub:
Using the device ID, key/certificate, MQTT endpoint, and topic you obtained in steps 2 and 3, publish data to your IoT hub using the MQTT protocol.
The data should be automatically forwarded to your log analytics workspace and be available for analysis.
One of the hurdles a company might run into when moving to Azure, especially with Azure Monitor and Log Analytics, is integration with Action Groups. Rarely are the actions of SMS or Email good enough to integrate with an internal Service Management system, so that leaves webhook as the simplest way to get data back into the datacenter. But that leaves one problem – Firewalls.
The Azure backend can change at any time, so it’s important to know what IP addresses the Action Group can originate from – and we can do that with Get-AZNetworkServiceTag.
To start, let’s install the az.network module. I am specifying allowclobber and force, to both update dependencies and upgrade existing modules. Make sure you are running or pwsh window or VSCode as an administrator.
install-module az.network -allowclobber -force
If you aren’t already connected, do a quick Connect-AzAccount. It might prompt you for a username/password, and will default to a subscription, so specify an alternative if necessary.
Once connected, we can run the Get-AZNetworkServiceTag cmdlet. We will specify what region we can to get the information for – in this case, EastUS2.
Get-AzNetworkServiceTag -Location eastus2
The ‘values’ property is what we are after. It contains a massive amount of resource types, regions, and address ranges. In our case, let’s just get the Action Groups, specifically for EastUS2.
This is another post in a series of posts by fellow MVP Billy York and myself on migration from on-prem automation to Azure. Check out his post here to see the full list.
One of the challenges that needs to be addressed with moving off an on-prem tool such as Orchestrator is how to trigger your automations. Almost all of the tools individually have a method to call them remotely – things such as webhooks, watchers, api endpoints, etc… In this post I would like to highlight how another Azure tool – Azure Event Grid – can prove a useful tool for correlation and centralization. If you need a quick refresher on Event Grids – check out this post. I’m not going to dig into the concepts of Event Grid, but I will walk through how to do a quick setup of Event Grid and get it ready to trigger your workflows.
The first thing we are going to do is create an Event Grid Topic – go to the appropriate resource group, and create a new resource – pick Event Grid Topic, and click ‘Create’.
Specify the event topic name, subscription, resource group, location, etc… The deployment will take a minute or two.
When it’s created, you should see something like this. Take note of the “+ Event Subscription” and the Topic Endpoint.
The topic endpoint is important – this is where you can forward events to from your on-prem resources in order to for event grid to pick them up. This URL takes a json payload (under 64kb in the general release version, with 64kb increments being charged separately – 1mb version in public preview now). Because I am who I am, I wrote a quick PowerShell script that could be used by your resources as a quick and dirty integration.
Subject – What the event subject would be, which is what we will key off of later for subscriptions – this is a personal preference. You can trigger from the event type in the basic editor, but I prefer subject.
eventTime – Required, in UTC
id – Important, but only if you want unique event identifiers.
data – The important bits from your on-prem resources – the bits we will want to pass to the Azure Automation resources.
After sending a couple of events, you can look at the ‘Published Events’ metric to ensure they are coming in as expected:
Now it’s time to give the event grid something to do when the events arrive. There are several ways to accomplish this – all done with a ‘subscription’ to the events. Some of the ‘automation’ flavored options include:
Azure Functions
WebHooks
Sending to Event Hubs
Service Bus Queues and Topics
WebHooks are pretty self-explanatory, but also one of the most powerful. For example, you can create a Logic App that is triggered by an http request, and from there break out and perform any type of automation that you want. I will go over that in another post. For this post, I will show a slightly more difficult to setup, but equally as powerful method to start automation – the Azure Function EventGrid triggered function. Head over to your Azure Function, and let’s add a new function:
Select the “Azure Event Grid trigger” and give it a name – in my case I gave it the descriptive name ” EventGridTrigger1″. After it’s created, you should see something like this:
You can see the parameters – eventGridEvent and TriggerMetadata. Keep those in mind. Now head back over to the Event Grid Topic, and let’s add a new subscription. When you select the endpoint in the new subscription, you should see your EventGridTrigger function:
Great – since the function is created already, the endpoint is something we can select. If the function wasn’t created, there would be no option to create a new one.
Now we can dig into the actual subscription properties – notice the 3 tabs. Basic, Filters, and Advanced Features. Filters is where we will do most filtering for automation, although some can be done in the basic tab via the event type. For now, just set the Event Type to ‘recordInserted ‘, since that is what we put in the PowerShell code, so we can switch over to the filters and do the rest of the work.
On the Filters tab, the first thing we want to do in this example is check the box marked “Enable subject filtering”. If you remember in the PowerShell, we set the filter to “App01/Database/TLogFull”. You could imagine this being the unique identifier to trigger the appropriate automation – almost something like a unique monitor ID or an automation trigger id. In this example, let’s set that as our filter. We will do this simple one in this post, but branch out and look at advanced features in a future one:
When you are ready to create your new subscription, head back to the ‘Basic’ tab and give it a name – numbers, letters, and dashes only. Do it right, and you will be greeted with something like this:
Now that we have the subscription created, let’s send some events and see if they trigger the subscription! If you run that PowerShell snippet a couple of times, wait a minute or two, and check out the ‘monitor’ tab of the EventGridTrigger function, you will see something like this:
And clicking on the details:
From here, we can see the data fields that were passed, and which could be used in our PowerShell function.
Hopefully you can see how using an Event Grid can help trigger your automations, especially when dealing with IOT and monitoring situations, or when a simple webhook is all you have to work with. They offer an easy way to take those PowerShell workflows from Orchestrator and directly import them into Azure with little modification, while at the same time providing a centralized method of tracking.