Using the agent scripting objects on a SCOM 2012 agent


<!--[if lt IE 9]>

<![endif]-->


Comments (16)

  1. Kevin Holman says:

    @OdgeUK –

    Yes – this will almost never work. The problem is that whatever you do in script – it is being called by a monitoringhost.exe process. When we kill the healthservices for a restart, we kill these worker processes – and they in turn kill any cscript.exe processes
    – which make the restart unreliable. If you look at the health service restart that Microsoft supplies for the agent resources – we actually call into WMI – and create a new process "out of band" which makes it reliable. I’d recommend looking at that example
    and seeing if you can reuse.

  2. Andrew says:

    I have scorch doing it for us, runs a task to add or remove a management group then runs the flush health service task which effectively reloads the configuration

  3. Tao Yang says:

    Nice one, Thanks Kevin! Also, I managed to use DCM from ConfigMgr 2012 to enforce the correct management group is configured on OpsMgr 2012 agents: http://blog.tyang.org/2013/11/30/deploying-opsmgr-202-r2-agents-using-configmgr-part-2/

  4. Sebastian says:

    We didn’t read the note about the Local Administaror Rights…and just wondered why the folks above are not stepped into this error.
    We found this workaround: Run schtasks.exe in a Wsshell.run to create a Scheduled Job executing the net stop , start commands. Some confirmation prompts of schtasks.exe was fulfilled with “schtasks.exe …. < Yesfile.txt". Of course Yesfile.txt was created in same script using Textfile.Write("Y"), TextFile.writeln() will not work. This jobmanagement was quite tricky, but now works.
    Thanks again to Kevin. We will use the script in our migration project.

  5. Tom Vergauwn says:

    Hi Kevin, thanks for this…
    I have a question, it seems the mp does not seem to discover agenst on windows xp? Do I need to different discovery method?

  6. Tom Vergauwen says:

    Found out… replacing the Target of the discovery “Windows!Microsoft.Windows.Server.OperatingSystem” with “Windows!Microsoft.Windows.OperatingSystem” did the trick.

  7. OdgeUK says:

    Having variable results with getting the Health Service to restart with a task. I’m running the Task with an account that is a member of an AD group which is, in turn, a member of the Administrators group on all our servers. Still however, I run into cases
    where after running task, the healthservice will stop but not start. Any idea why this might be?

    Thanks

  8. OdgeUK says:

    Thanks Kevin! That sounds about right (althought it DOES work on a number of servers, but not on others, which I find a bit wierd). Will check into the Out of Band restart you have in your script. I wonder why we restart the Health Service? Doesn’t Call
    objMSConfig.ReloadConfiguration make the changes effective anyway?

  9. OdgeUK says:

    This monitor is working really well in identifying agents with old management groups. However, I have found that it’s not picking up R2 servers. Any reason this might be?

  10. DKS says:

    I deployed `add management group to existing agent’ vb script using SCCM 2007 but didn’t work however works fine when I ran it . Any idea how to overcome this issue?

  11. andyinsdca says:

    The MP/script works like a champ. BUT (and this is a HUGE one…) it’s case sensitive on the removal of an MG. For example if you have myoldmg in the registry and the script is attempting to delete MYOLDMG, it won’t work. The monitor works just fine, oddly
    enough.

  12. SCOM 2012R2- Afternoon, Is there a powershell script or some other tool you could reference that would make “multihoming many agents” not such a time consuming task? My environment has approx 450+ servers (and growing), around half currently have agents on them, but not all are multihomed. My goal is to get agents on all the servers and have them multihomed, We have three tiers (Test/Dev( 1 mgmt svr), QC(2 mgmt srvs) and Production(2 mgmt srvs). I want to end up with all the agents reporting up to Production but have them also homed to thier respective tiers? Is this possible? For currently installed and future ones? I am told that doing so will make creating dashboards and views for mon itoring much more successful/easier…?
    Thanks as always for you time and brain power!
    Tony

  13. Barry Dysert says:

    I have a very simple problem, but I don’t know where to post it. Maybe here?

    I’m simply trying to invoke an external program from SCOM. I’ve tried invoking an .exe, a .bat, a .ps1, and a .vbs. All my code works (the .exe that’s called simply creates a dummy file on a network share). I can invoke these in any fashion, e.g., the command line, on any machine. The only thing that doesn’t’ work is that SCOM won’t invoke my external entity regardless if it’s a .ps1, .vbs, etc. Does this have something to do with management packs, or am I just not creating the rule right? Thanks.

    1. Kevin Holman says:

      It is totally possible.

      Not easy to write in the console – so I’d start by writing a task.

      A task uses the same datasource – which is System.CommandExecuterProbe

      Here is an example: https://gallery.technet.microsoft.com/SQL-Server-RunAs-Addendum-0c183c32

      OR – write a simple timed script rule – and have a simple vbscript call your command. That you can do easily in the console.

  14. Brian Wright says:

    In the above “ManagementServiceConfigurationClass.AddManagementGroup
    This method adds a new, but inactive, management group to the agent. ” What if, I want this new MG active on the agent? Does a flush/restart need to happen?

Skip to main content