次の方法で共有


Who is connected to Service Manager?

I've been asked a few times recently how to identify who is connected to a Service Manager Management Server. There are several ways to get the list of users currently connected, so I thought I'd share some of them here.

First up – How MANY users are connected?

Before we look at how to see who is connected to a Management Server, I wanted to look at how to simply see how many people are connected. The easiest way to do this is from perfmon on the Management Server.

Using the counter OpsMgr SDK Service\Client Connections Using Cache. This will give you read of connections to the Data Access Service in real time.

 

OPTION 1 – Using the SCOM PowerShell Module

Operations Manager has a nifty & simple way of getting the currently connected users via PowerShell. Unfortunately, this same functionality isn't available in the Service Manager PowerShell interface. However, due to the shared infrastructure in System Center, we can actually use the Operations Manager shell to query Service Manager.

Whenever you install the Operations Manager console, you'll also get the "Operations Manager Shell". This will open up the Operations Manager PowerShell module and connect to your Operations Manager Management Server.

First, we can disconnect from Operations Manager, then point it at a Service Manager Management Server instead. We can then simply query for the list of connected users:

Get-SCOMManagementGroupConnection | Remove-SCOMManagementGroupConnection

New-SCOMManagementGroupConnection -ComputerName SERVICEMANAGERSERVER

(Get-SCOMManagementGroup).GetConnectedUserNames()

 

This will give us the list of the currently logged on users to a Service Manager Management Server:

 

OPTION 2 – Using .Net

Alternatively we can use the .Net interface into Service Manager. This is an updated version of what's been previously posted at https://blogs.technet.com/b/servicemanager/archive/2010/02/01/getting-a-list-of-connected-users.aspx, as many folks had a problem running it.

Here we're using the GetConnectedUserNames method on the EnterpriseManagementGroup class, as per https://msdn.microsoft.com/en-us/library/gg460200.aspx.

 

EnterpriseManagementGroup emg = new EnterpriseManagementGroup(managementServer);

foreach (String userName in emg.GetConnectedUserNames())

{

Console.WriteLine(userName.ToString());

}

 

I've attached a Visual Studio project, which includes the SMConnections.exe which is ready to run.

You can run: "SMConnections.exe" from the command line, which will default to localhost to run on the Management Server. Alternatively you can run "SMConnections.exe SERVERNAME" to remotely connect to a Management Server.

 

OPTION 3 – Using Orchestrator

Another way we can do this is in Orchestrator, using the 'Run .Net Script' activity.

In the 'Initialize Data' activity, I've created 1 string input, called managementServer.

In 'Run .Net Script', I set the language to C# and input the following:

Note, I've looped through the users, adding each to a variable called userNameList, separating each with a comma and space.

On the advanced tab, I've added in the reference & Namespaces. You'll have to point to the Service Manager SDK binary, which is available at C:\Program Files\Microsoft System Center 2012 R2\Service Manager\SDK Binaries\Microsoft.EnterpriseManagement.Core.dll. We're using the namespaces 'System' and 'Microsoft.EnterpriseManagement'.

Finally, I've published out the userNameList variable from the code:

The final activity can write the output however you like. I used a 'Send platform event', but it'd be a good idea to write to a log, DB, etc.

SMConnections.zip