Getting CI count on the basis of class(server,switch etc.,) (2025)

What about this kind of script:



var gr = new GlideRecord('cmn_location');


gr.addNotNullQuery('name');


gr.query();




while (gr.next()){


var grn = new GlideAggregate('cmdb_ci');


grn.addQuery('location', gr.sys_id);


grn.addAggregate('count', 'sys_class_name');


grn.orderByAggregate('count', 'sys_class_name');


grn.groupBy('sys_class_name');


grn.query();


while (grn.next()) {


gs.log('Location: ' + gr.name.getDisplayValue() + ' has = ' + grn.getAggregate('count', 'sys_class_name') + ' CIs in class: ' + grn.sys_class_name.getDisplayValue());


}


}


gives on my own instance:


[0:00:00.804] Script completed in scope global: script


*** Script: Location: 2-10-1 Yurakucho, Chiyoda-ku, Tokyo has = 37 CIs in class: Computer
*** Script: Location: 2-10-1 Yurakucho, Chiyoda-ku, Tokyo has = 1 CIs in class: Rack
*** Script: Location: 755 Hank Aaron Dr SW, Atlanta GA has = 2 CIs in class: Computer
*** Script: Location: San Diego has = 1 CIs in class: JavaServer
*** Script: Location: San Diego has = 1 CIs in class: Business Service
*** Script: Location: 2-12-1 Ookayama, Meguro-ku, Tokyo has = 24 CIs in class: Computer
*** Script: Location: 248 Abbotsford Road, Brisbane has = 20 CIs in class: Computer
*** Script: Location: 248 Abbotsford Road, Brisbane has = 1 CIs in class: Rack
*** Script: Location: Karmelitska 2, Lesser Town, Prague has = 25 CIs in class: Computer
*** Script: Location: Karmelitska 2, Lesser Town, Prague has = 1 CIs in class: Rack
*** Script: Location: 3385 Ross Clark Cir, Dothan AL has = 2 CIs in class: Computer
*** Script: Location: 1390 S Colorado Blvd, Denver CO has = 10 CIs in class: Computer
*** Script: Location: 194 S Dupont Hwy, New Castle DE has = 1 CIs in class: Network Gear
*** Script: Location: 8695 NW 13th Ter, Doral FL has = 4 CIs in class: Computer
*** Script: Location: 3015 GRAND AVE, Coconut Grove FL has = 1 CIs in class: Network Gear
*** Script: Location: 8609 Mills Drive, Miami FL has = 30 CIs in class: Computer
*** Script: Location: 5464 Wendy Bagwell Pkwy, Hiram GA has = 1 CIs in class: Computer
*** Script: Location: 2102 Old 41 Hwy Nw, Kennesaw GA has = 4 CIs in class: Computer
*** Script: Location: 6785 Tara Blvd, Jonesboro GA has = 2 CIs in class: Computer
*** Script: Location: 9159 S Cicero Ave, Oak Lawn IL has = 4 CIs in class: Computer
*** Script: Location: 4395 Fox Valley Center Dr, Aurora IL has = 5 CIs in class: Computer
*** Script: Location: 660 N Wells St, Chicago IL has = 2 CIs in class: Computer
*** Script: Location: 222 Friend St, Boston MA has = 2 CIs in class: Computer
*** Script: Location: 6411 Nw Barry Rd, Kansas City MO has = 5 CIs in class: Computer
*** Script: Location: 3030 High Point Rd, Greensboro NC has = 5 CIs in class: Computer
*** Script: Location: 3030 High Point Rd, Greensboro NC has = 2 CIs in class: Computer Peripheral
*** Script: Location: 3030 High Point Rd, Greensboro NC has = 1 CIs in class: Printer
*** Script: Location: 211 W 56th St, New York NY has = 12 CIs in class: Computer
*** Script: Location: 211 W 56th St, New York NY has = 4 CIs in class: Linux Server
*** Script: Location: 453 Miamisburg Centerville Road, Dayton OH has = 1 CIs in class: Computer
*** Script: Location: 10536 N Kings Hwy, North Myrtle Beach SC has = 4 CIs in class: Computer
*** Script: Location: 750 N Riverside Dr, Clarksville TN has = 14 CIs in class: Computer
*** Script: Location: 4224 Preston Rd, Frisco TX has = 2 CIs in class: Computer
*** Script: Location: 5101 Belt Line Rd, Dallas TX has = 2 CIs in class: Computer
*** Script: Location: 2519 Southwest Fwy, Houston TX has = 3 CIs in class: Computer
*** Script: Location: SHS quadra 5, Bloco E., Brasilia has = 11 CIs in class: Computer
*** Script: Location: Carretera Cancun-Chetumal KM 22, Cancun has = 11 CIs in class: Computer
*** Script: Location: Carrera 54 No. 49 - 31, Medellin has = 20 CIs in class: Computer
*** Script: Location: Rome has = 1 CIs in class: Printer
*** Script: Location: 150 Kennedy Road, Hong Kong has = 8 CIs in class: Computer
*** Script: Location: 150 Kennedy Road, Hong Kong has = 1 CIs in class: Rack
*** Script: Location: Bockenheimer Landstraße 223, Frankfurt has = 28 CIs in class: Computer
*** Script: Location: 75-85 York Street, Melbourne has = 8 CIs in class: Computer
*** Script: Location: 140 George Street, Sydney has = 10 CIs in class: Computer
*** Script: Location: 30 Katharinenstr, Hamburg has = 32 CIs in class: Computer
*** Script: Location: 750 3rd Ave, New York NY has = 2 CIs in class: Computer
*** Script: Location: 750 3rd Ave, New York NY has = 2 CIs in class: Business Service
*** Script: Location: 750 3rd Ave, New York NY has = 1 CIs in class: Data Center
*** Script: Location: 750 3rd Ave, New York NY has = 1 CIs in class: Network Gear
*** Script: Location: 750 3rd Ave, New York NY has = 1 CIs in class: Service Offering
*** Script: Location: 8500 Andrew Carnegie Boulevard, Charlotte NC has = 1 CIs in class: Network Gear
*** Script: Location: 8500 Andrew Carnegie Boulevard, Charlotte NC has = 1 CIs in class: Business Service
*** Script: Location: Denver has = 1 CIs in class: Business Service
*** Script: Location: Via Nomentana 56, Rome has = 28 CIs in class: Computer
*** Script: Location: Via Nomentana 56, Rome has = 8 CIs in class: Windows Server
*** Script: Location: 2500 West Daming Road, Shanghai has = 25 CIs in class: Computer
*** Script: Location: 3 Whitehall Court, London has = 78 CIs in class: Computer
*** Script: Location: 3 Whitehall Court, London has = 1 CIs in class: Rack
*** Script: Location: 27, Boulevard Vitton, Paris has = 78 CIs in class: Computer
*** Script: Location: Bockenheimer Landstraße 123, Frankfurt has = 42 CIs in class: Computer
*** Script: Location: Bockenheimer Landstraße 123, Frankfurt has = 7 CIs in class: UNIX Server
*** Script: Location: Salem has = 1 CIs in class: Business Service
*** Script: Location: 123 West Plaza, Solana Beach CA has = 12 CIs in class: Computer
*** Script: Location: Americas has = 3 CIs in class: Service Offering
*** Script: Location: Emea has = 1 CIs in class: Service Offering
*** Script: Location: Apac has = 1 CIs in class: Service Offering
*** Script: Location: Paradise Road, Richmond, London has = 42 CIs in class: Computer
*** Script: Location: Paradise Road, Richmond, London has = 2 CIs in class: Service Offering
*** Script: Location: 820 E St., Central, San Diego CA has = 33 CIs in class: Computer
*** Script: Location: 3795 Fairmount Ave., City Heights/Weingart, San Diego CA has = 9 CIs in class: Server
*** Script: Location: 3795 Fairmount Ave., City Heights/Weingart, San Diego CA has = 3 CIs in class: Mass Storage Device
*** Script: Location: 3795 Fairmount Ave., City Heights/Weingart, San Diego CA has = 2 CIs in class: AIX Server
*** Script: Location: 2920 Burgener Blvd., Clairemont, San Diego CA has = 3 CIs in class: Computer
*** Script: Location: 925 W. Washington St., Mission Hills, San Diego CA has = 5 CIs in class: Computer
*** Script: Location: 4616 Clairemont Drive, North Clairemont, San Diego CA has = 10 CIs in class: Server
*** Script: Location: 101 W. San Ysidro Blvd., San Ysidro, San Diego CA has = 1 CIs in class: Network Gear
*** Script: Location: 5148 Market St., Valencia Park/Malcolm X, San Diego CA has = 4 CIs in class: Computer
*** Script: Location: 200 West 1st Street, Santa Ana, CA has = 29 CIs in class: Computer
*** Script: Location: 200 West 1st Street, Santa Ana, CA has = 21 CIs in class: Printer
*** Script: Location: 832 Imperial Beach Blvd, San Diego, CA has = 13 CIs in class: Computer
*** Script: Location: 4430 Camino De La Plaza, San Ysidro, CA has = 10 CIs in class: Computer
*** Script: Location: 13518 Poway Road, Poway, CA has = 13 CIs in class: Computer
*** Script: Location: 12305 Dennery Road, San Diego, CA has = 17 CIs in class: Computer
*** Script: Location: 542 Crescent Road, Escondido CA has = 7 CIs in class: Computer
*** Script: Location: 100 Park Boulevard, San Diego, CA has = 19 CIs in class: Computer
*** Script: Location: 100 Park Boulevard, San Diego, CA has = 5 CIs in class: Printer



Regards,

Sergiu


View solution in original post

Getting CI count on the basis of class(server,switch etc.,) (2025)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Gov. Deandrea McKenzie

Last Updated:

Views: 5767

Rating: 4.6 / 5 (46 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Gov. Deandrea McKenzie

Birthday: 2001-01-17

Address: Suite 769 2454 Marsha Coves, Debbieton, MS 95002

Phone: +813077629322

Job: Real-Estate Executive

Hobby: Archery, Metal detecting, Kitesurfing, Genealogy, Kitesurfing, Calligraphy, Roller skating

Introduction: My name is Gov. Deandrea McKenzie, I am a spotless, clean, glamorous, sparkling, adventurous, nice, brainy person who loves writing and wants to share my knowledge and understanding with you.