Installing OMS and Service Map Agents with PowerShell

Back in January this year I wrote a post about how you can install the OMS agent using PowerShell. Now the time has come to include the Service Map agent in the equation as well since this is a feature that recently got Generally Available. You can find the original post about installing the OMS agent here. What´s new in this script is that I have added a section for downloading and installing the Service Map agent as well. Enough talking, let´s get to it!


You will of course need the script, which you can download from my TechNet Gallery here. Download it and place is somewhere where you will find it the next time you want to use it. 😊

See the script below;

Alright, so the script is in place. Lets´s rock and roll!

Before you can run the script you´re going to need two things.

  1. Your Workspace ID
  2. Your Workspace Primary Key

Head over to the OMS portal and step into Settings -> Connected Sources -> Windows Servers. Copy the Workspace ID and the Primary Key as seen below.

Running the script
You need to run the script as an administrator, and you will also need internet access from the server to download the files. However, if you don´t have internet access you could always download the agents somewhere else and copy it to the folder C:\Source and the agent would be installed by the script.

See below what it looks like running the script. You will be asked to put in the Workspace ID and the Workspace Key that you just looked up.

The agents are downloaded to the folder.

And you´re done installing the agents. You´re ready to go Service Mapping. 😊

Just to show you what it looks like, the two agents are installed and good to go.

This query will show you all the Windows servers (and clients for that matter) that are communicating with Log Analytics. As you can see, the TBGW01 server are also communicating now that the agents are installed.

The query to use: Type=Heartbeat OSType=Windows | top 500000 | dedup SourceComputerId | Sort Computer | display Table

Looking at the Service Map solution in the OMS portal will show you something like below.

And then you will have your server assesses using the Service Map agent as you can see below.

I hope this will help you out in installing OMS and Service Map agents in your environment. I have deactivated the section in the script that deletes the C:\Source folder when the installation is done. This is simply because you shouldn´t delete the folder if you have any other important files in there. Feel free to use the line if you want to, but you will need to activate it yourself by editing the script and removing the lines 83 and 94.

If you want to know more about Service Map, you can check out my previous posts, A first look at OMS Service Map and A deeper look at OMS Service Map.

If there are any questions, just leave a comment below and I´ll get back as soon as possible. Otherwise, have fun deploying agents in your environment 😊

5 thoughts on “Installing OMS and Service Map Agents with PowerShell Add Yours?

  • Great Job Daniel. What if I don’t to be asked for the workspace id. I just want to deploy this script on multiple servers.

    • You shouldn’t have to do anything else than simply ignoring the workspaceID and workspaceKey switches. I’m not able to try it out at this moment since I’m still on holiday and nowhere near a server.

      Try it out and let me know how it goes, otherwise I’ll see if I can give you an updated script.


  • Hi Daniel,

    And big thanks for you work. Is this possible to set de WorkSpaceID and WorkSpaceKey instead ask them?

    • Hi Greg,
      Sure you can! Just delete the lines 8 through 18 and replace them with the following;
      $WorkSpaceID = “Your Workspace ID here”
      $WorkSpaceKey = “Your Workspace key here”

      That should make it easier for you to run the script on a batch of servers and not having to paste the information on each server.

      Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *

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

%d bloggers like this: