Пример #1
0
        public static string test()
        {
            RunspaceConfiguration rconfig = RunspaceConfiguration.Create();
            PSSnapInException Pwarn = new PSSnapInException();
            Collection<PSObject> results = new Collection<PSObject>();
            Runspace runspace = RunspaceFactory.CreateRunspace();

            string test = "Import-Module -Name virtualmachinemanager\r\n";
            runspace = RunspaceFactory.CreateRunspace(rconfig);
            runspace.Open();

            Pipeline pipeline;

            pipeline = runspace.CreatePipeline();
            pipeline.Commands.AddScript(test);

            try {
                results = pipeline.Invoke();
                Console.WriteLine("Worked");
                return "";
            }
            catch (Exception ex) {
                Console.WriteLine("Failed "+ex.Message);
                return ex.Message;
            }
        }
Пример #2
0
        /// <exception cref="PSArgumentNullException">
        /// mshSnapInID is null.
        /// </exception>
        /// <exception cref="PSArgumentException">
        /// mshSnapInID is either a default mshsnapin or not loaded.
        /// </exception>
        internal override PSSnapInInfo DoRemovePSSnapIn(string name, out PSSnapInException warning)
        {
            warning = null;

            if (_consoleInfo == null)
            {
                return(null);
            }

            s_mshsnapinTracer.WriteLine("Removing mshsnapin {0}", name);

            PSSnapInInfo mshsnapinInfo = _consoleInfo.RemovePSSnapIn(name);

            UnloadPSSnapIn(mshsnapinInfo, out warning);

            s_mshsnapinTracer.WriteLine("MshSnapin {0} removed", name);

            return(mshsnapinInfo);
        }
        internal override PSSnapInInfo DoAddPSSnapIn(
            string name,
            out PSSnapInException warning)
        {
            warning = (PSSnapInException)null;
            RunspaceConfigForSingleShell._mshsnapinTracer.WriteLine("Adding mshsnapin {0}", (object)name);
            if (this._consoleInfo == null)
            {
                return((PSSnapInInfo)null);
            }
            PSSnapInInfo mshsnapinInfo;

            try
            {
                mshsnapinInfo = this._consoleInfo.AddPSSnapIn(name);
            }
            catch (PSArgumentException ex)
            {
                RunspaceConfigForSingleShell._mshsnapinTracer.TraceError(ex.Message);
                RunspaceConfigForSingleShell._mshsnapinTracer.WriteLine("Adding mshsnapin {0} failed.", (object)name);
                throw;
            }
            catch (PSArgumentNullException ex)
            {
                RunspaceConfigForSingleShell._mshsnapinTracer.TraceError(ex.Message);
                RunspaceConfigForSingleShell._mshsnapinTracer.WriteLine("Adding mshsnapin {0} failed.", (object)name);
                throw;
            }
            if (mshsnapinInfo == null)
            {
                return((PSSnapInInfo)null);
            }
            this.LoadPSSnapIn(mshsnapinInfo, out warning);
            if (warning != null)
            {
                RunspaceConfigForSingleShell._mshsnapinTracer.TraceWarning("There was a warning when loading mshsnapin {0}: {1}", (object)name, (object)warning.Message);
            }
            RunspaceConfigForSingleShell._mshsnapinTracer.WriteLine("MshSnapin {0} added", (object)name);
            return(mshsnapinInfo);
        }
Пример #4
0
        private void UnloadPSSnapIn(PSSnapInInfo mshsnapinInfo, out PSSnapInException warning)
        {
            warning = null;

            if (mshsnapinInfo != null)
            {
                this.Cmdlets.RemovePSSnapIn(mshsnapinInfo.Name);
                this.Providers.RemovePSSnapIn(mshsnapinInfo.Name);
                this.Assemblies.RemovePSSnapIn(mshsnapinInfo.Name);
                this.Types.RemovePSSnapIn(mshsnapinInfo.Name);
                this.Formats.RemovePSSnapIn(mshsnapinInfo.Name);

                string errors;
                UpdateAll(out errors);

                if (!String.IsNullOrEmpty(errors))
                {
                    s_mshsnapinTracer.TraceWarning(errors);
                    warning = new PSSnapInException(mshsnapinInfo.Name, errors, true);
                }
            }
        }
Пример #5
0
        internal override PSSnapInInfo DoAddPSSnapIn(string name, out PSSnapInException warning)
        {
            warning = null;
            _mshsnapinTracer.WriteLine("Adding mshsnapin {0}", new object[] { name });
            if (this._consoleInfo == null)
            {
                return(null);
            }
            PSSnapInInfo mshsnapinInfo = null;

            try
            {
                mshsnapinInfo = this._consoleInfo.AddPSSnapIn(name);
            }
            catch (PSArgumentException exception)
            {
                _mshsnapinTracer.TraceError(exception.Message, new object[0]);
                _mshsnapinTracer.WriteLine("Adding mshsnapin {0} failed.", new object[] { name });
                throw;
            }
            catch (PSArgumentNullException exception2)
            {
                _mshsnapinTracer.TraceError(exception2.Message, new object[0]);
                _mshsnapinTracer.WriteLine("Adding mshsnapin {0} failed.", new object[] { name });
                throw;
            }
            if (mshsnapinInfo == null)
            {
                return(null);
            }
            this.LoadPSSnapIn(mshsnapinInfo, out warning);
            if (warning != null)
            {
                _mshsnapinTracer.TraceWarning("There was a warning when loading mshsnapin {0}: {1}", new object[] { name, warning.Message });
            }
            _mshsnapinTracer.WriteLine("MshSnapin {0} added", new object[] { name });
            return(mshsnapinInfo);
        }
Пример #6
0
        private void LoadPSSnapIn(PSSnapInInfo mshsnapinInfo, out PSSnapInException warning)
        {
            string str;

            warning = null;
            try
            {
                this.LoadPSSnapIn(mshsnapinInfo);
            }
            catch (PSSnapInException)
            {
                if (!mshsnapinInfo.IsDefault)
                {
                    this._consoleInfo.RemovePSSnapIn(mshsnapinInfo.Name);
                }
                throw;
            }
            this.UpdateAll(out str);
            if (!string.IsNullOrEmpty(str))
            {
                _mshsnapinTracer.TraceWarning("There was a warning while loading mshsnapin {0}:{1}", new object[] { mshsnapinInfo.Name, str });
                warning = new PSSnapInException(mshsnapinInfo.Name, str, true);
            }
        }
Пример #7
0
 public PSSnapInInfo AddPSSnapIn(string name, out PSSnapInException warning)
 {
     return this.DoAddPSSnapIn(name, out warning);
 }
Пример #8
0
 internal virtual PSSnapInInfo DoRemovePSSnapIn(
     string name,
     out PSSnapInException warning)
 {
     throw RunspaceConfiguration.tracer.NewNotSupportedException();
 }
Пример #9
0
 public PSSnapInInfo ImportPSSnapIn(string name, out PSSnapInException warning)
 {
     throw new NotImplementedException();
 }
Пример #10
0
        private void UnloadPSSnapIn(PSSnapInInfo mshsnapinInfo, out PSSnapInException warning)
        {
            warning = null;

            if (mshsnapinInfo != null)
            {
                this.Cmdlets.RemovePSSnapIn(mshsnapinInfo.Name);
                this.Providers.RemovePSSnapIn(mshsnapinInfo.Name);
                this.Assemblies.RemovePSSnapIn(mshsnapinInfo.Name);
                this.Types.RemovePSSnapIn(mshsnapinInfo.Name);
                this.Formats.RemovePSSnapIn(mshsnapinInfo.Name);

                string errors;
                UpdateAll(out errors);

                if (!String.IsNullOrEmpty(errors))
                {
                    s_mshsnapinTracer.TraceWarning(errors);
                    warning = new PSSnapInException(mshsnapinInfo.Name, errors, true);
                }
            }
        }
Пример #11
0
        /// <exception cref="PSArgumentNullException">
        /// mshSnapInID is null.
        /// </exception>
        /// <exception cref="PSArgumentException">
        /// mshSnapInID is either a default mshsnapin or not loaded.
        /// </exception>
        internal override PSSnapInInfo DoRemovePSSnapIn(string name, out PSSnapInException warning)
        {
            warning = null;

            if (_consoleInfo == null)
                return null;

            s_mshsnapinTracer.WriteLine("Removing mshsnapin {0}", name);

            PSSnapInInfo mshsnapinInfo = _consoleInfo.RemovePSSnapIn(name);

            UnloadPSSnapIn(mshsnapinInfo, out warning);

            s_mshsnapinTracer.WriteLine("MshSnapin {0} removed", name);

            return mshsnapinInfo;
        }
Пример #12
0
        /// <summary>
        /// Loads a Monad Console file specified by <paramref name="path"/>
        /// </summary>
        /// <param name="path">
        /// The absolute path from which the content is loaded.
        /// </param>
        /// <param name="cle">
        /// PSConsoleLoadException occurred while loading this console file. This object
        /// also contains specific PSSnapInExceptions that occurred while loading.
        /// </param>
        /// <returns>
        /// A list of <see cref="PSSnapInInfo"/> objects specified in the console file.
        /// </returns>
        /// <exception cref="PSArgumentNullException">
        /// Path is null.
        /// </exception>
        /// <exception cref="PSArgumentException">
        /// 1. Path does not specify proper file extension.
        /// 2. PSSnapInId doesnt contain valid characters.
        /// 3. Path is not an Absolute Path.
        ///    Example of valid paths:"\\MyDir\\MyFile.txt" and "C:\\MyDir".
        /// </exception>
        /// <exception cref="ArgumentException">
        /// path contains one or more of the invalid characters defined in System.IO.Path.InvalidPathChars.
        /// </exception>
        /// <exception cref="XmlException">
        /// Unable to load/parse the file specified by path.
        /// </exception>
        private Collection <PSSnapInInfo> Load(string path, out PSConsoleLoadException cle)
        {
            // Initialize the out parameter..
            cle = null;

            s_mshsnapinTracer.WriteLine("Load mshsnapins from console file {0}", path);

            if (string.IsNullOrEmpty(path))
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            // Check whether the path is an absolute path
            if (!Path.IsPathRooted(path))
            {
                s_mshsnapinTracer.TraceError("Console file {0} needs to be a absolute path.", path);

                throw PSTraceSource.NewArgumentException("path", ConsoleInfoErrorStrings.PathNotAbsolute, path);
            }

            if (!path.EndsWith(StringLiterals.PowerShellConsoleFileExtension, StringComparison.OrdinalIgnoreCase))
            {
                s_mshsnapinTracer.TraceError("Console file {0} needs to have {1} extension.", path, StringLiterals.PowerShellConsoleFileExtension);

                throw PSTraceSource.NewArgumentException("path", ConsoleInfoErrorStrings.BadConsoleExtension);
            }

            PSConsoleFileElement consoleFileElement;

            // exceptions are thrown to the caller
            consoleFileElement = PSConsoleFileElement.CreateFromFile(path);

            // consoleFileElement will never be null..
            if (!Utils.IsPSVersionSupported(consoleFileElement.MonadVersion))
            {
                s_mshsnapinTracer.TraceError("Console version {0} is not supported in current monad session.", consoleFileElement.MonadVersion);

                throw PSTraceSource.NewArgumentException("PSVersion", ConsoleInfoErrorStrings.BadMonadVersion, consoleFileElement.MonadVersion,
                                                         PSVersion.ToString());
            }

            // Create a store for exceptions
            Collection <PSSnapInException> exceptions = new Collection <PSSnapInException>();

            foreach (string mshsnapin in consoleFileElement.PSSnapIns)
            {
                try
                {
                    this.AddPSSnapIn(mshsnapin);
                }
                catch (PSArgumentException ae)
                {
                    PSSnapInException sle = new PSSnapInException(mshsnapin, ae.Message, ae);

                    // Eat ArgumentException and continue..
                    exceptions.Add(sle);
                }
                catch (System.Security.SecurityException se)
                {
                    string            message = ConsoleInfoErrorStrings.PSSnapInReadError;
                    PSSnapInException sle     = new PSSnapInException(mshsnapin, message, se);
                    // Eat SecurityException and continue..

                    exceptions.Add(sle);
                }
            }

            // Before returning check whether there are any exceptions
            if (exceptions.Count > 0)
            {
                cle = new PSConsoleLoadException(this, exceptions);
            }

            // We are able to load console file and currently monad engine
            // can service this. So mark the isdirty flag.
            IsDirty = false;

            return(_externalPSSnapIns);
        }
Пример #13
0
        /// <summary>
        /// Loads a Monad Console file specified by <paramref name="path"/>
        /// </summary>
        /// <param name="path">
        /// The absolute path from which the content is loaded.
        /// </param>
        /// <param name="cle">
        /// PSConsoleLoadException occurred while loading this console file. This object
        /// also contains specific PSSnapInExceptions that occurred while loading.
        /// </param>
        /// <returns>
        /// A list of <see cref="PSSnapInInfo"/> objects specified in the console file.
        /// </returns>
        /// <exception cref="PSArgumentNullException">
        /// Path is null.
        /// </exception>
        /// <exception cref="PSArgumentException">
        /// 1. Path does not specify proper file extension.
        /// 2. PSSnapInId doesnt contain valid characters.
        /// 3. Path is not an Absolute Path. 
        ///    Example of valid paths:"\\MyDir\\MyFile.txt" and "C:\\MyDir".
        /// </exception>
        /// <exception cref="ArgumentException">
        /// path contains one or more of the invalid characters defined in System.IO.Path.InvalidPathChars.
        /// </exception>
        /// <exception cref="XmlException">
        /// Unable to load/parse the file specified by path.
        /// </exception>
        private Collection<PSSnapInInfo> Load(string path, out PSConsoleLoadException cle)
        {
            // Initialize the out parameter..
            cle = null;

            s_mshsnapinTracer.WriteLine("Load mshsnapins from console file {0}", path);

            if (string.IsNullOrEmpty(path))
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            // Check whether the path is an absolute path
            if (!Path.IsPathRooted(path))
            {
                s_mshsnapinTracer.TraceError("Console file {0} needs to be a absolute path.", path);

                throw PSTraceSource.NewArgumentException("path", ConsoleInfoErrorStrings.PathNotAbsolute, path);
            }

            if (!path.EndsWith(StringLiterals.PowerShellConsoleFileExtension, StringComparison.OrdinalIgnoreCase))
            {
                s_mshsnapinTracer.TraceError("Console file {0} needs to have {1} extension.", path, StringLiterals.PowerShellConsoleFileExtension);

                throw PSTraceSource.NewArgumentException("path", ConsoleInfoErrorStrings.BadConsoleExtension);
            }

            PSConsoleFileElement consoleFileElement;

            // exceptions are thrown to the caller
            consoleFileElement = PSConsoleFileElement.CreateFromFile(path);

            // consoleFileElement will never be null..
            if (!Utils.IsPSVersionSupported(consoleFileElement.MonadVersion))
            {
                s_mshsnapinTracer.TraceError("Console version {0} is not supported in current monad session.", consoleFileElement.MonadVersion);

                throw PSTraceSource.NewArgumentException("PSVersion", ConsoleInfoErrorStrings.BadMonadVersion, consoleFileElement.MonadVersion,
                    PSVersion.ToString());
            }

            // Create a store for exceptions
            Collection<PSSnapInException> exceptions = new Collection<PSSnapInException>();

            foreach (string mshsnapin in consoleFileElement.PSSnapIns)
            {
                try
                {
                    this.AddPSSnapIn(mshsnapin);
                }
                catch (PSArgumentException ae)
                {
                    PSSnapInException sle = new PSSnapInException(mshsnapin, ae.Message, ae);

                    // Eat ArgumentException and continue..
                    exceptions.Add(sle);
                }
                catch (System.Security.SecurityException se)
                {
                    string message = ConsoleInfoErrorStrings.PSSnapInReadError;
                    PSSnapInException sle = new PSSnapInException(mshsnapin, message, se);
                    // Eat SecurityException and continue..

                    exceptions.Add(sle);
                }
            }

            // Before returning check whether there are any exceptions
            if (exceptions.Count > 0)
            {
                cle = new PSConsoleLoadException(this, exceptions);
            }

            // We are able to load console file and currently monad engine
            // can service this. So mark the isdirty flag.
            IsDirty = false;

            return _externalPSSnapIns;
        }
Пример #14
0
 public PSSnapInInfo AddPSSnapIn(string name, out PSSnapInException warning)
 {
     return(this.DoAddPSSnapIn(name, out warning));
 }
Пример #15
0
 /// <summary>
 /// Remove a PSSnapin from runspace configuration.
 /// </summary>
 /// <remarks>
 /// This member provides logic for removing PSSnapin. 
 ///
 /// RunspaceConfiguration derived class should not override this member.
 /// </remarks>
 /// <param name="name">name of the PSSnapin</param>
 /// <param name="warning">warning message</param>
 /// <returns></returns>
 public PSSnapInInfo RemovePSSnapIn(string name, out PSSnapInException warning)
 {
     return DoRemovePSSnapIn(name, out warning);
 }
Пример #16
0
 internal virtual PSSnapInInfo DoRemovePSSnapIn(string name, out PSSnapInException warning)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Пример #17
0
 internal override PSSnapInInfo DoAddPSSnapIn(string name, out PSSnapInException warning)
 {
     warning = null;
     _mshsnapinTracer.WriteLine("Adding mshsnapin {0}", new object[] { name });
     if (this._consoleInfo == null)
     {
         return null;
     }
     PSSnapInInfo mshsnapinInfo = null;
     try
     {
         mshsnapinInfo = this._consoleInfo.AddPSSnapIn(name);
     }
     catch (PSArgumentException exception)
     {
         _mshsnapinTracer.TraceError(exception.Message, new object[0]);
         _mshsnapinTracer.WriteLine("Adding mshsnapin {0} failed.", new object[] { name });
         throw;
     }
     catch (PSArgumentNullException exception2)
     {
         _mshsnapinTracer.TraceError(exception2.Message, new object[0]);
         _mshsnapinTracer.WriteLine("Adding mshsnapin {0} failed.", new object[] { name });
         throw;
     }
     if (mshsnapinInfo == null)
     {
         return null;
     }
     this.LoadPSSnapIn(mshsnapinInfo, out warning);
     if (warning != null)
     {
         _mshsnapinTracer.TraceWarning("There was a warning when loading mshsnapin {0}: {1}", new object[] { name, warning.Message });
     }
     _mshsnapinTracer.WriteLine("MshSnapin {0} added", new object[] { name });
     return mshsnapinInfo;
 }
Пример #18
0
 internal override PSSnapInInfo DoRemovePSSnapIn(string name, out PSSnapInException warning)
 {
     warning = null;
     if (this._consoleInfo == null)
     {
         return null;
     }
     _mshsnapinTracer.WriteLine("Removing mshsnapin {0}", new object[] { name });
     PSSnapInInfo mshsnapinInfo = this._consoleInfo.RemovePSSnapIn(name);
     this.UnloadPSSnapIn(mshsnapinInfo, out warning);
     _mshsnapinTracer.WriteLine("MshSnapin {0} removed", new object[] { name });
     return mshsnapinInfo;
 }
Пример #19
0
 private void LoadPSSnapIn(PSSnapInInfo mshsnapinInfo, out PSSnapInException warning)
 {
     string str;
     warning = null;
     try
     {
         this.LoadPSSnapIn(mshsnapinInfo);
     }
     catch (PSSnapInException)
     {
         if (!mshsnapinInfo.IsDefault)
         {
             this._consoleInfo.RemovePSSnapIn(mshsnapinInfo.Name);
         }
         throw;
     }
     this.UpdateAll(out str);
     if (!string.IsNullOrEmpty(str))
     {
         _mshsnapinTracer.TraceWarning("There was a warning while loading mshsnapin {0}:{1}", new object[] { mshsnapinInfo.Name, str });
         warning = new PSSnapInException(mshsnapinInfo.Name, str, true);
     }
 }
Пример #20
0
        /// <exception cref="PSArgumentNullException">
        /// mshSnapInID is empty or null.
        /// </exception>
        /// <exception cref="PSArgumentException">
        /// PSSnapIn is already loaded.
        /// No PSSnapIn with given id found.
        /// PSSnapIn cannot be loaded.
        /// </exception>
        /// <exception cref="System.Security.SecurityException">
        /// Caller doesn't have permission to read keys.
        /// </exception>
        internal override PSSnapInInfo DoAddPSSnapIn(string name, out PSSnapInException warning)
        {
            warning = null;

            s_mshsnapinTracer.WriteLine("Adding mshsnapin {0}", name);

            if (_consoleInfo == null)
                return null;

            PSSnapInInfo mshsnapinInfo = null;

            try
            {
                mshsnapinInfo = _consoleInfo.AddPSSnapIn(name);
            }
            catch (PSArgumentException mae)
            {
                s_mshsnapinTracer.TraceError(mae.Message);
                s_mshsnapinTracer.WriteLine("Adding mshsnapin {0} failed.", name);
                throw;
            }
            catch (PSArgumentNullException mane)
            {
                s_mshsnapinTracer.TraceError(mane.Message);
                s_mshsnapinTracer.WriteLine("Adding mshsnapin {0} failed.", name);
                throw;
            }

            if (mshsnapinInfo == null)
                return null;

            LoadPSSnapIn(mshsnapinInfo, out warning);

            if (warning != null)
            {
                s_mshsnapinTracer.TraceWarning("There was a warning when loading mshsnapin {0}: {1}", name, warning.Message);
            }

            s_mshsnapinTracer.WriteLine("MshSnapin {0} added", name);

            return mshsnapinInfo;
        }
Пример #21
0
 private void UnloadPSSnapIn(PSSnapInInfo mshsnapinInfo, out PSSnapInException warning)
 {
     warning = null;
     if (mshsnapinInfo != null)
     {
         string str;
         this.Cmdlets.RemovePSSnapIn(mshsnapinInfo.Name);
         this.Providers.RemovePSSnapIn(mshsnapinInfo.Name);
         this.Assemblies.RemovePSSnapIn(mshsnapinInfo.Name);
         this.Types.RemovePSSnapIn(mshsnapinInfo.Name);
         this.Formats.RemovePSSnapIn(mshsnapinInfo.Name);
         this.UpdateAll(out str);
         if (!string.IsNullOrEmpty(str))
         {
             _mshsnapinTracer.TraceWarning(str, new object[0]);
             warning = new PSSnapInException(mshsnapinInfo.Name, str, true);
         }
     }
 }
Пример #22
0
        private void LoadPSSnapIn(PSSnapInInfo mshsnapinInfo, out PSSnapInException warning)
        {
            warning = null;

            try
            {
                LoadPSSnapIn(mshsnapinInfo);
            }
            catch (PSSnapInException)
            {
                if (!mshsnapinInfo.IsDefault)
                    _consoleInfo.RemovePSSnapIn(mshsnapinInfo.Name);

                // exception during load mshsnapin are fatal. 
                throw;
            }

            string errors;

            UpdateAll(out errors);

            if (!String.IsNullOrEmpty(errors))
            {
                s_mshsnapinTracer.TraceWarning("There was a warning while loading mshsnapin {0}:{1}", mshsnapinInfo.Name, errors);

                warning = new PSSnapInException(mshsnapinInfo.Name, errors, true);
            }
        }
Пример #23
0
 /// <summary>
 /// Remove a PSSnapin from runspace configuration.
 /// </summary>
 /// <remarks>
 /// This member provides logic for removing PSSnapin.
 ///
 /// RunspaceConfiguration derived class should not override this member.
 /// </remarks>
 /// <param name="name">name of the PSSnapin</param>
 /// <param name="warning">warning message</param>
 /// <returns></returns>
 public PSSnapInInfo RemovePSSnapIn(string name, out PSSnapInException warning)
 {
     return(DoRemovePSSnapIn(name, out warning));
 }
Пример #24
0
		public PSSnapInInfo RemovePSSnapIn (string name, out PSSnapInException warning)
		{
			throw new NotImplementedException ();
		}
Пример #25
0
 internal virtual PSSnapInInfo DoRemovePSSnapIn(string name, out PSSnapInException warning)
 {
     throw PSTraceSource.NewNotSupportedException();
 }
Пример #26
0
 private Collection<PSSnapInInfo> Load(string path, out PSConsoleLoadException cle)
 {
     cle = null;
     _mshsnapinTracer.WriteLine("Load mshsnapins from console file {0}", new object[] { path });
     if (string.IsNullOrEmpty(path))
     {
         throw PSTraceSource.NewArgumentNullException("path");
     }
     if (!Path.IsPathRooted(path))
     {
         _mshsnapinTracer.TraceError("Console file {0} needs to be a absolute path.", new object[] { path });
         throw PSTraceSource.NewArgumentException("path", "ConsoleInfoErrorStrings", "PathNotAbsolute", new object[] { path });
     }
     if (!path.EndsWith(".psc1", StringComparison.OrdinalIgnoreCase))
     {
         _mshsnapinTracer.TraceError("Console file {0} needs to have {1} extension.", new object[] { path, ".psc1" });
         throw PSTraceSource.NewArgumentException("path", "ConsoleInfoErrorStrings", "BadConsoleExtension", new object[] { "" });
     }
     PSConsoleFileElement element = PSConsoleFileElement.CreateFromFile(path);
     if (!Utils.IsPSVersionSupported(element.MonadVersion))
     {
         _mshsnapinTracer.TraceError("Console version {0} is not supported in current monad session.", new object[] { element.MonadVersion });
         throw PSTraceSource.NewArgumentException("PSVersion", "ConsoleInfoErrorStrings", "BadMonadVersion", new object[] { element.MonadVersion, this.psVersion.ToString() });
     }
     Collection<PSSnapInException> exceptions = new Collection<PSSnapInException>();
     foreach (string str in element.PSSnapIns)
     {
         try
         {
             this.AddPSSnapIn(str);
         }
         catch (PSArgumentException exception)
         {
             PSSnapInException item = new PSSnapInException(str, exception.Message, exception);
             exceptions.Add(item);
         }
         catch (SecurityException exception3)
         {
             string pSSnapInReadError = ConsoleInfoErrorStrings.PSSnapInReadError;
             PSSnapInException exception4 = new PSSnapInException(str, pSSnapInReadError, exception3);
             exceptions.Add(exception4);
         }
     }
     if (exceptions.Count > 0)
     {
         cle = new PSConsoleLoadException(this, exceptions);
     }
     this.isDirty = false;
     return this.externalPSSnapIns;
 }
Пример #27
0
 public PSSnapInInfo RemovePSSnapIn(string name, out PSSnapInException warning) => this.DoRemovePSSnapIn(name, out warning);