示例#1
0
        /// <summary>
        /// Tests that a given connection is valid and can be opened.
        /// </summary>
        /// <param name="connectionInfo">The connection information.</param>
        public bool TestConnection(PSConnectionInfo connectionInfo)
        {
            if (connectionInfo == null)
            {
                throw new ArgumentNullException(nameof(connectionInfo));
            }

            try
            {
                using (var pshell = new PSClient())
                {
                    pshell.Open(connectionInfo);
                    pshell.Close();
                }

                return(true);
            }
            catch (PSRemotingTransportException)
            {
                return(false);
            }
            catch (OperationCanceledException)
            {
                return(false);
            }
        }