Monitor your Azure RemoteApp environment with OpInsight – Part 1


With this blogpost I want to explain how you can connect your existing Azure RemoteApp environment with Azure Operational Insights. Operational Insights is part of the Operations Management Suite and is a cloud monitoring solution which can be used to collect information from different sources. In this blogpost I want to focus on adding a Hybrid Azure RemoteApp collection to OpInsight. In coming blogposts, I will explain what Azure Operational Insights can monitor from the Azure RemoteApp environments.

The first step is to create a OpInsight environment. You can do this by going to this link and create your own free OpInsight environment. When you have your Operational Insights environment you only have to connect clients to this environment. In our scenario we first want to add an Azure RemoteApp environment. My goal is to do this through updating the Master Image. When my collection is updated with this Master Image the instances should be automatically added to Azure Operational Insights. The only problem is that you need to configure the Microsoft Monitoring agent after the deployment of an instance. I have created the following solution which meets my goals of adding instances automatically to Azure OpInsight. Execute the following steps:

  1. Create a VM with based on your previous Master Image
  2. Download the Microsoft Monitoring Agent from the OpInsight Portal
  3. Install the Microsoft Monitoring Agent on your Master Image VM without connecting to an environment.
  4. After the installation reboot your Master Image VM
  5. After the reboot stop the ‘Microsoft Monitoring Agent Service’
  6. Save the following script locally on your Master Image VM. Replace Master VM Name with your own Master VM Computername, workspace id with your own workspace id and replace workspace key with your own workspace key. Script:
    if ($env:computername -ne "Master VM Name") {
        $healthServiceSettings = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg'
        $opinsight_enabled = $healthServiceSettings.AzureOperationalInsightsEnabled
        if( $opinsight_enabled -eq $false) {
            Write-Verbose "OpInsight will be enabled"
            #Remove Existing MMA certificates
            Get-ChildItem -Path 'Cert:\LocalMachine\Operations Manager' | Remove-Item
            #Enable OpInsight on MMA
            $healthServiceSettings.EnableAzureOperationalInsights('workspace id', 'workspace key')
            #Restart the MMA
            Restart-Service -Name 'HealthService'
            Write-Verbose "OpInsight is enabled"
         } else {
            Write-Verbose "OpInsight is already enabled"
  7. The next step is to put the above script in a scheduled task. Configure the scheduled task as follows:
    1. On the first screen give it a name and description
    2. As trigger use ‘At System Startup’
    3. As Action use the following
      Program/Script: C:\Windows\System32\windowspowershell\v1.0\powershell.exe
      Arguments: -Command “& C:\_install\configure_mmaagent.ps1”
    4. In the properties of the task change the Run As user tot ‘SYSTEM’ and check the following checkbox: ‘Run with highest privileges’
  8. The next step is to prepare the ConfigMgr client for imaging. The following actions need to be executed:
    1. Stop the ‘SMS Agen Host’ Service.
    2. Delete the ConfigMgr certificates from the Local Machine Certificate store.
    3. Remove the %SYSTEMROOT%\SMSCFG.ini file.
  9. The last step is to execute SysPrep by running the following command:
    C:\Windows\System32\sysprep\sysprep.exe /generalize /oobe /shutdown

Next step is to upload the new Master Image into Azure RemoteApp. When the image is uploaded apply this new update to your Azure RemoteApp collection. When the updates process is finished you should see that the instances will be added to your Operational Insights environment:


You can check if the Microsoft Monitoring Agent is working as it should by checking the eventlog of an Azure RemoteApp instance and look into the Operations Manager eventlog for the event:


In the second part of this blogseries I want to focus on adding solutions to the Operational Insights environment which are usable in an Azure RemoteApp scenario.

If you have any questions please let me know!

6 thoughts on “Monitor your Azure RemoteApp environment with OpInsight – Part 1

  1. Jason Bank

    Where does the .AzureOperationalInsightsEnabled managment group come from for this script? I cant seem to find it in my standard azure image

    • Arjan Vroege

      Hi Jason,

      Sorry for my late reply. You first need to install the Microsoft Monitoring Agent. When installed you can create the ComObject and use .AzureOperationalInsightsEnabled. Please drop me an email if you need more help.

      Regards, Arjan

Leave a Reply

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