A friend of mine posted a query that in their customer environment, they have a good number of Remote ConfigMgr Console installed and some of the consoles are not closed since last 1 month and more. Hence as a best practice, they wanted to close the ConfigMgr console which are opened than ‘X’ days.
Although there is a console view in latest version of ConfigMgr server called ‘Console Connections’, but it doesn’t allow to close any remote console.
Hence, to achieve the goal to close all console which are opened than X days, we need the following:
- A ConfigMgr Collection about all the machine where ConfigMgr console is installed.
- CMPivot magic to get the machine details where ConfigMgr console opened since last X days.
- PowerShell Script to close the console remotely.
- Use PS Script in CMPivot output.
So, here is the details about all the steps:
- ConfigMgr Console Collection:
We can use the following WQL query to create a dynamic collection about all the machine where ConfigMgr Console is installed:
select * from SMS_R_System inner join SMS_G_System_SERVICE on SMS_G_System_SERVICE.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_INSTALLED_SOFTWARE on SMS_G_System_INSTALLED_SOFTWARE.ResourceID = SMS_R_System.ResourceId where SMS_G_System_INSTALLED_SOFTWARE.ProductName like “%Configuration Manager Console%”
The output of the query looks like:

- CMPivot Magic
Now that we have a collection ready, we can use CMPivot against that collection. Here is the way how we can use this:

Now the CMPivot is ready to run against this collection:

The Kusto query which will help us to get the ConfigMgr Console opened is:
Process | where Name == ‘Microsoft.ConfigurationManagement.exe’
Here is the screenshot of it:

Let’s verify the PID from the machine:
‘Viksahay-ConfigMgr’ machine :

‘ConfigMgr-SQL’ Machine:

Now the important point to note is the to find the ConfigMgr Console opened and older than X days, so the ‘CreationDate’ column of the above output will give me the desired value.
So, lets me try to create a Kusto query of machine having ConfigMgr Console opened and older than 7 days (you can use the day as per your own requirement). The query would be:
Process | where Name == ‘Microsoft.ConfigurationManagement.exe’ and CreationDate <= ago(7d)
The output should ideally give me only 1 machine (Viksahay-ConfigMgr) as it was opened since 7th Feb 2020. So here is how the output look like:

Now , as we got all the ConfigMgr console opened since last 1 week, so let’s take an action to close them. To achieve it, we will create a ‘PS Script’ and will use the ‘Scripts’ feature of ConfigMgr.
- Creating Script in ConfigMgr:
Here is how we can create a script to kill a ConfigMgr Console process:
- Create script in ConfigMgr console:
ConfigMgr Console | Software Library | Scripts | Right Click and choose ‘Create Script’
Here is how the wizard look like:

We will use the simple PS command to close a ConfigMgr console process. The command is:
Stop-Process -Name “Microsoft.ConfigurationManagement” -Force
Follow the wizard and complete it.
- Approve the script:
A script in ConfigMgr can only be used, once its approved. Here is the way how you can approve the script:

- If the ‘Approve/Deny’ option is grayed out, adjust the following ‘Hierarchy setting’ appropriately:

d) Now the script is ready to be used in CMPivot Result.
4) Use PS Script in CMPivot output.
- As the output of the CMPivot was looking like

Note: As I have only 1 machine matching the criteria, hence I am only selecting one. If you have multiple machine the criteria, do a multi select.
- Select the machine(s) | Right Click and Choose ‘Run Script’

- Choose the appropriate PS Script which you created in last step.

- Follow the wizard and make sure that it gets complete successfully.
- You can also monitor the running of the script from:
Monitoring | Client Operations.
- Monitor the script execution statistics under: Monitoring / Script Status
You can see the Script Execution State, the Exit Code and the Output
On Client Machine:
Script download location: C:\Windows\CCM\ScriptStore
Logs location: C:\Windows\CCM\logs\Scipts.log
Hope this will help you close all the ConfigMgr console opened since last X days. Although I just demonstrated it for ConfigMgr Console, you can use this solution for any other Remote Console installed and opened since last X days.
You must log in to post a comment.