Example #1
0
        /// <summary>
        /// Connects this instance.
        /// </summary>
        /// <exception cref="System.Exception">Unable to connect</exception>
        public void connect()
        {
            Runspace RemoteRunspace = null;

            if (Client != null)
            {
                Client.Dispose();
            }

            //suppress exceptions
            try
            {
                WSMan.openRunspace(connectionInfo, ref RemoteRunspace);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                PSCode.TraceInformation(ex.Message);
            }

            //Check if connection was successful...
            if (RemoteRunspace.RunspaceStateInfo.State == RunspaceState.Opened)
            {
                //Yes, return Runspace
                remoteRunspace = RemoteRunspace;

                Client = new ccm(remoteRunspace, PSCode);
                //oAgentProperties = new agentProperties(remoteRunspace, PSCode);
                //oSoftwareDistribution = new softwareDistribution(remoteRunspace, PSCode);
            }
            else
            {
                //No, throw an execption...
                throw new Exception("Unable to connect");
            }
        }