开发者

Detect maintenance mode scom agent (aka MOM)

Is there a way programatically to find out if the S开发者_如何学GoCOM agent is in Maintenance Mode.


This could be done by calling cmdlets.

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

Add Reference to 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();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜