locked
Is there a more efficient way in SCOM to pull windows computers? RRS feed

  • Question

  • Does anyone know of a more efficient way to pull computer names?  I have over 600 computers and this take a long time.


    My Code:

                ComputerDDList1.Items.Clear();
                ManagementGroup mg = new ManagementGroup(connectionInfo);
                
                MonitoringClassCriteria compCriteria = new MonitoringClassCriteria("Name = 'Microsoft.Windows.Computer'");
                ReadOnlyCollection<MonitoringClass> compClasses = mg.GetMonitoringClasses(compCriteria);
                ReadOnlyCollection<PartialMonitoringObject> compObjects = mg.GetPartialMonitoringObjects(compClasses[0]);

                foreach (PartialMonitoringObject compObject in compObjects)
                {
                    ComputerDDList1.Items.Add(compObject.Name);
                }

    Wednesday, September 30, 2009 3:26 PM

Answers

  • In a large environment this is a select * where class type = any derivative of Microsoft.Windows.Computer.  There can be many of these.  Do you want to further specialize - Microsoft.Windows.Server.Computer?


    Microsoft Corporation
    Tuesday, October 20, 2009 2:19 AM

All replies

  • What's your ultimate goal?  To simply get a list?  Doing direct SQL queries will be the fastest.  Unfortunately, the structure of the OpsMgr 2007 has never been published to my knowledge.
    Wednesday, September 30, 2009 7:37 PM
  • I agree that SQL is fastest but I would like to stay out of hitting sql as I don't have permissions.

    I just want to pull a list of windows servers into a dropdown box.  I have alot of other code in my app but the parts where I hit the SDK seem to be the slowest.  There has got to be a faster way.


    Wednesday, September 30, 2009 8:26 PM
  • In a large environment this is a select * where class type = any derivative of Microsoft.Windows.Computer.  There can be many of these.  Do you want to further specialize - Microsoft.Windows.Server.Computer?


    Microsoft Corporation
    Tuesday, October 20, 2009 2:19 AM
  • Nope just pull the list of all Windows Computers and put them in a dropdown box.  Can you show me in C# code?
    Friday, October 23, 2009 7:51 PM
  • You mentioned earlier that you're query is pulling in 600 or so computer names...  Are those *all* relevant to your query?  I *think* that is what Dan is alluding to: you choosing a better query to get less results/a faster query.

    (PS Do you only really want the names?  I wonder if you are more specific on what your collection contains, when you create it, then maybe when you try to go through each element to add it, it may go faster.)

    (PSS Is your list of computurs relatively static?  Maybe try pre-generating the list or even saving it to a text file?)
    Saturday, October 24, 2009 10:16 AM
  • Hey Marco,

    I understand what Dan is alluding to but yes they are all relevant.  I want to populate a dropdown with the names of all "Windows" computers managed with SCOM.  This should be a simple task.  The problem is the only way to do it is the way I described above and it is super slow.  There has to be a better way.
    Sunday, October 25, 2009 3:23 AM
  • No activity for 30 days, will mark this thread as answered now. Feel free to open it again.


    Anders Bengtsson | Microsoft MVP - Operations Manager | http://www.contoso.se
    Thursday, December 17, 2009 10:05 PM
  • I have a similar problem with a script that reads from a text file and does a foreach on each entry putting each one into maintenance mode. It has to finish putting each server into maintenance mode before going to the next server. When you get over a hundred it can take a very long time. Is there a way to have it just do each one and not wait before going to the next line? Code:

    param($rootMS,$minutesMM,$comment,$textFile)
    $servername = Get-Content $textFile

    Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin;
    Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin;
    new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin;
    set-location $rootMS -ErrorVariable errSnapin;

    ForEach ($srv in $servername)

    {

    $computerPrincipalName = $agent.displayname
    $computerPrincipalName

    $computerClass = get-monitoringclass -name:Microsoft.Windows.Computer

    $computerCriteria = "PrincipalName='" + $computerPrincipalName + "'"
    $Computer = Get-MonitoringObject -monitoringclass:$ComputerClass | where {$_.PathName -match $srv}
    $startTime = [System.DateTime]::Now
    $endTime = $startTime.AddMinutes($minutesMM)

    "Putting " + $computer + " into maintenance mode"
    New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$computer -comment:$comment

    }

    Friday, February 12, 2010 10:51 PM
  • Posting to a thread that is marked as answered might delay a response...

    To speed up your foreach loop, move out as much as you can.

    #1. The line:
    $computerClass = get-monitoringclass -name:Microsoft.Windows.Computer

    Move it before your foreach loop, then use $computerClass within the foreach.

    #2. This part:
    Get-MonitoringObject -monitoringclass:$ComputerClass

    Move it before your foreach loop, and save the data to a variable to use within your foreach.

    #3. These lines:
    $startTime = [System.DateTime]::Now
    $endTime = $startTime.AddMinutes($minutesMM)

    Move them before your foreach loop.



    Wednesday, February 17, 2010 10:02 PM
  • Thanks Marco! I'll go ahead and try that.
    Thursday, February 18, 2010 2:05 AM
  • Easier said than done, for me at least! Assuming I can get the above to work, does anyone know how to take the input from the command: c:\net group (ad group name) /domain > list.txt?

    If you do that command you'll see the file is formatted in a way that is somewhat like a table. I know how to do line by line but how about this?

    Yes I know it's time I go to a PowerShell class, I'm trying to get my company to pay for one ;)
    Thursday, February 18, 2010 5:03 PM
  • Or if you are really good, take the AD group name as a parameter into the same PowerShell script and do it all in one script?
    Thursday, February 18, 2010 5:04 PM