Gaining a Powershellcontext in SCOM 2012 as in SCVMM 2012 Powershellcontext class RRS feed

  • Question

  • hi all,

    I have a problem in using the Powershell command SDK in System center operation manager 2012, where we can use the PS cmdlets .NET api provided in SCOM 2012. In order to make the cmdlet class work we need Powershell context type of class present in SCVMM 2012, the code looks like this for SCVMM2012

    //We use the local assemblies stored at bin folder to locate the scvmm powershell modules,
    //you could also using the scvmm console installation folder by retrieving it from registry
    //psContext = new PowerShellContext(1, 5, string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, @"bin\"));

    PowerShellContext PSContext = new PowerShellContext(string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, @"bin\"));

    with this context i can use the SCVMM cmdlets like this

    public List<VMInfo> GetVirtualMachinesByHost(VMMWebServiceContext serviceContext, string hostName)
    List<VMInfo> vmList = new List<VMInfo>();
    Host host = GetHostByHostName(serviceContext, hostName);
    GeneratedCommand<VM> command = GetSCVirtualMachine.Create(new GetSCVirtualMachine.ParameterSets.VMHostGroupSet(host) { VMMServer = serviceContext.VMMServer });
    serviceContext.PSContext.BeginInvoke<VM>(command, new AsyncCallback(CallBack), null);
    InvocationResults<VM> results = serviceContext.PSContext.EndInvoke<VM>(asyncState);

    //we are using Windows auth here, you need to configure the Application Pool is running under an account with
    //sufficient privileges to connect to scvmm and is able to perform required operations

    same type of class i need in SCOM 2012, by which i can execute the cmdlets classes, sync or async mode to obtain the results from the scom 2012 server .

    Ofcourse there is .NET SDK which we can use to get the results, but this we are finding easy , once we have the base code found.

    can anyone out there can provide me some light on this, so that i can proceed with the usage.


    Thanks in advance


    Tuesday, November 29, 2011 5:39 AM