检测维护模式scom代理(又名MOM)

时间:2010-08-08 00:21:41

标签: mom

是否有一种方法可以确定SCOM代理是否处于维护模式。

1 个答案:

答案 0 :(得分:0)

可以通过调用cmdlet来完成。

Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client
Get-Agent 

添加引用 System.Management.Automation.dll

public class ExecuteCmdlet
{
    public static InitialSessionState state;
    public static RunspacePool pool;

    static ExecuteCmdlet()
    {
        Console.WriteLine("Creating Initial State");
        state = InitialSessionState.CreateDefault();
        try
        {
            PSSnapInException ex = null;
            state.ImportPSSnapIn("Microsoft.EnterpriseManagement.OperationsManager.Client", out ex);
        }
        catch { }

        pool = RunspaceFactory.CreateRunspacePool(state);
        pool.SetMinRunspaces(3);
        pool.SetMaxRunspaces(10);
        pool.Open();
    }

     public static Collection<PSObject> Execute(string cmd)
    {
        PowerShell gpc = PowerShell.Create();
        // Specify the runspace to use and add commands.
        gpc.RunspacePool = pool;
        gpc.AddCommand(cmd);
        return gpc.Invoke();
    }
}