EducationSoftwareStrategy.com
StrategyCommunity

Knowledge Base

Product

Community

Knowledge Base

TopicsBrowse ArticlesDeveloper Zone

Product

Download SoftwareProduct DocumentationSecurity Hub

Education

Tutorial VideosSolution GalleryEducation courses

Community

GuidelinesGrandmastersEvents
x_social-icon_white.svglinkedin_social-icon_white.svg
Strategy logoCommunity

© Strategy Inc. All Rights Reserved.

LegalTerms of UsePrivacy Policy
  1. Home
  2. Topics

KB486766: How to List User Privileges for All Active Users Using a Python Script in MicroStrategy Workstation


Rainiero Leon

Support Engineer • MicroStrategy


The article outlines a Python script designed to enumerate the privileges of all active users within a specific MicroStrategy environment. Utilizing the mstrio-py library, the script streamlines the process, thereby improving administrative efficiency and oversight.

Symptom

Administrators in the Strategy Workstation may find it challenging to manually track and list the privileges assigned to each active user. This manual process can be cumbersome and prone to errors, necessitating a solution to streamline the task.

Cause

The need for this script stems from the administrative challenge of manually listing the privileges of each active user in a given Strategy environment, which can be time-consuming and prone to errors.

Solution

To automate the listing of user privileges for all active users, adhere to the following steps in the Strategy WorkStation:
1. Connect to Your Environment: Initialize the connection to your Strategy environment.
2. Navigate to Administration: Access the administration panel to manage scripts and workflows.
3. Access Scripts Section: Go to the scripts section where you can create or modify scripts.
4. Select Your Environment: Choose the appropriate environment where the script will be executed.
5. Open Gallery Tab: In the right section of the interface, select the Gallery tab to view available workflows and scripts.
6. Expand Administration Workflows: Find and expand the Administration Workflows section to access various administrative scripts.
7. Launch 'List Active User Privileges' Script: Double-click on the 'list active user privileges' script to open it.
8. Execute the Script: Press the run button to execute the script, which will automatically list the privileges of all active users.

ka0PW0000002CDBYA2_0EMPW000006YyHd.jpeg

Here is the Python script in Workstation that facilitates this operation:


"""List user privileges for all active users."""

from typing import List

from mstrio.connection import Connection, get_connection
from mstrio.users_and_groups import list_users

def list_active_user_privileges(connection: "Connection") -> List[dict]:
    """List user privileges for all active users.

    Args:
        connection: Strategy connection object returned by
            `connection.Connection()`

    Returns:
        list of dicts where each of them is in given form:
        {
            'id' - id of user
            'name' - name of user
            'username' - username of user
            'privileges' - list of privileges of user
        }
    """
    all_users = list_users(connection=connection)
    active_users = [u for u in all_users if u.enabled]
    privileges_list = []
    for usr in active_users:
        p = {
            'id': usr.id, 'name': usr.name, 'username': usr.username, 'privileges': usr.privileges
        }
        print(f"{p['name']} ({p['username']}) ", flush=True)
        for prvlg in p['privileges']:
            print("\t" + prvlg['privilege']['name'], flush=True)
        privileges_list.append(p)
    return privileges_list

# connect to environment without providing user credentials
# variable `workstationData` is stored within Workstation
conn = get_connection(workstationData, 'Strategy Tutorial')

# list privileges for all enabled users
list_active_user_privileges(conn)

 

Related articles

  1. Python within Workstation: https://www2.Strategy.com/producthelp/Current/Workstation/en-us/Content/intro_scripts.htm 
  2. Preview Python Scripts: https://www2.Strategy.com/producthelp/Current/Workstation/en-us/Content/preview_scripts.htm
  3. mstrio-py: https://github.com/MicroStrategy/mstrio-py 
  4. https://www2.Strategy.com/producthelp/Current/Workstation/en-us/Content/intro_scripts.htm

Customization Warning:


This customization is provided as a convenience to Strategy users and is only directly applicable to the version stated. While this code may apply to other releases directly, Strategy Technical Support makes no guarantees that the code provided will apply to any future or previous builds. In the event of a code change in future builds, Strategy Technical Support makes no guarantee that an updated version of this particular customization will be provided. For enhancements to this customization or to incorporate similar functionality into other versions, contact your Account Executive to inquire about Strategy Consulting assistance.
 


Comment

0 comments

Details

Knowledge Article

Published:

June 7, 2024

Last Updated:

June 7, 2024