Skip to main content

WMI Script to retrieve SSRS Configurations

For retrieving the SQL Server Reporting Services configurations using custom program in C# or .NET we need to use WMI (Windows Management Instrumentation) script. The process involves the following steps.

RETRIEVING WMI NAMESPACE FOR SSRS
For retrieving the WMI namespace we write the following function.

 
public static string GetNamespace(string machineName)
 {
   string rSroot = @"root\Microsoft\SqlServer\ReportServer";
   string strNamespace = "";
   System.Management.ManagementClass mc = new ManagementClass(new    ManagementScope(@"root\Microsoft\SqlServer\ReportServer"), new ManagementPath("__namespace"), null);
            foreach (ManagementObject ns in mc.GetInstances())
            {
                if (ns["Name"].ToString().Contains("RS_"))
                {
                    rSroot = rSroot + "\\" + ns["Name"].ToString();
                }
            }

            System.Management.ManagementClass mc1 = new ManagementClass(new ManagementScope(rSroot), new ManagementPath("__namespace"), null);
            foreach (ManagementObject ns in mc1.GetInstances())
            {
                if (ns["Name"].ToString().Contains("v"))
                {
                    rSroot = rSroot + "\\" + ns["Name"].ToString();
                }
            }
            System.Management.ManagementClass mc2 = new ManagementClass(new ManagementScope(rSroot), new ManagementPath("__namespace"), null);
            foreach (ManagementObject ns in mc2.GetInstances())
            {
                if (ns["Name"].ToString().Contains("Admin"))
                {
                    rSroot = rSroot + "\\" + ns["Name"].ToString();
                }
            }
            strNamespace = rSroot;
            return strNamespace;
        }

RETRIEVING WMI CLASS FOR SSRS
The above function accepts system name/ IP address as parameter. Once we get the namespace for reporting service, we pass the same to the below function to get the associated class which contains the report server configuration.

public static string GetClass(string strNamespace)
        {
            string ClassName = "";
            ManagementClass newRSClass = new ManagementClass(strNamespace);
            EnumerationOptions options = new EnumerationOptions();
            options.EnumerateDeep = true; // set to false if only the root classes
            ManagementObjectCollection mo = newRSClass.GetSubclasses(options);
            foreach (ManagementObject ob in mo)
            {
                if (ob["__Class"].ToString().Contains("MSRep"))
                    ClassName = ob["__Class"].ToString();
              
            }
            return ClassName;
        }

RETRIEVING SSRS CONFIGURATION PROPERTIES
Once we have retrieved the Class Name then we refer to class and try to get the configuration info through the below code.

public static void ReportServerProperties(string strNamespace, string ClassName)
        {
            ManagementClass serverClass;
            ManagementScope scope;
            try
            {
                scope = new ManagementScope(strNamespace);
                scope.Connect();
                serverClass = new ManagementClass(ClassName);
                serverClass.Get();
                if (serverClass == null)
                    throw new Exception("No class found");
                ManagementObjectCollection instances = serverClass.GetInstances();
                foreach(ManagementObject mo in instances)
                {
                    Console.WriteLine("Instances detected");
                    PropertyDataCollection props = mo.Properties;
                    foreach (PropertyData propData in props)
                    {
                        string name = propData.Name;
                        string value = propData.Value != null ? propData.Value.ToString() : "NULL";
                        Console.WriteLine(name + " " + value);
                    }
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }           
        }
 

 

Comments

Popular posts from this blog

DataZen Syllabus

INTRODUCTION TO DATAZEN PRODUCT ELEMENTS ARCHITECTURE DATAZEN ENTERPRISE SERVER INTRODUCTION SERVER ARCHITECTURE INSTALLATION SECURITY CONTROL PANEL WEB VIEWER SERVER ADMINISTRATION CREATING AND PUBLISHING DASHBOARDS CONNECTING TO DATASOURCES DESIGNER CONFIGURING NAVIGATOR CONFIGURING VISUALIZATION  PUBLISHING DASHBOARD WORKING WITH MAP  WORKING WITH DRILL THROUGH DASHBOARDS

PowerBI Interview Questions and Answers

Power BI Interview Questions – General Questions 1). What is self-service business intelligence? Ans: Self-Service Business Intelligence (SSBI) is an approach to data analytics that enables business users to filter, segment, and, analyse their data, without the in-depth technical knowledge in statistical analysis, business intelligence (BI). SSBI has made it easier for end users to access their data and create various visuals to get better business insights. Anybody who has basic understanding of the data can create reports to build intuitive and shareable dashboards. 2). What are the parts of Microsoft self-service business intelligence solution? Ans: Microsoft has two parts for Self-Service BI  Excel BI Toolkit – It allows users to create interactive report by importing data from different sources and model data according to report requirement.  Power BI – It is the online solution that enables you to share the interactive reports and queries that you have created using ...

MS BI Syllabus

Microsoft Business Intelligence Course Syllabus SSRS – SQL Server Reporting Services  Getting Started 1. Understanding Reporting (Authoring,Management,Delivery) 2. Installing Reporting (Native Mode, SharePoint Integration mode) 3. Building your first report  Authoring Reports 1. Developing Basic Reports (RDL,wizard,designer,datasource,dataset,formatting) 2. Working with expressions (expression to calculate value, Agg functions, exp for objects) 3. Organizing Data (Data Regions, Table, Matrix, Chart, List) 4. Advance Report (Parameter, drill down, drill through, links, 5. Report Model (Data Source, Data Source View, Model , Report Builder 3.0)  Managing Report ( Report Manager) 1. Managing Content (deploying report, folders, linked reports, datasources, value etc) 2. Managing Security (Item Level , Site navigation, localhost – sql) 3. Managing Server Config (Config Manager, Report Manager, Report Server DB)  Delivering Report 1. Accessing Report (Viewing...