protected override void EndProcessing()
        {
            if (!NoEnd)
            {
                switch (this.OutputAs)
                {
                case OutputAs.String:
                {
                    byte[] bytes = outStr.GetBytes();
                    base.WriteObject(Encoding.UTF8.GetString(bytes));
                    break;
                }

                case OutputAs.PSCredential:
                {
                    var userName = _dynLib.GetParameterValue <string>(USERNAME);
                    var psCreds  = new PSCredential(userName, outStr.AsSecureString());
                    base.WriteObject(psCreds);
                    break;
                }

                case OutputAs.SecureString:
                    base.WriteObject(outStr.AsSecureString());
                    break;

                case OutputAs.NetworkCredential:
                {
                    NetworkCredential netCreds = null;
                    string            un       = _dynLib.GetParameterValue <string>(USERNAME);
                    SecureString      ss       = outStr.AsSecureString();

                    netCreds = _dynLib.ParameterHasValue(DOMAIN)
                            ? new NetworkCredential(un, ss, _dynLib.GetParameterValue <string>(DOMAIN))
                            : new NetworkCredential(un, ss);

                    base.WriteObject(netCreds);
                    break;
                }

                case OutputAs.SqlCredential:
                {
                    var sqlCreds = new SqlCredential(_dynLib.GetParameterValue <string>(USERNAME), outStr.AsSecureString());
                    base.WriteObject(sqlCreds);
                    break;
                }
                }
            }
        }
Beispiel #2
0
        protected override void EndProcessing()
        {
            taskCount = Tasks.Count;
            if (SearchMethod != BROWSER)
            {
                IList <SqlInstanceResult> list = base.ProcessTasksWithProgressOutput(Tasks).ToList();
                if (this.MyInvocation.BoundParameters.ContainsKey("Name"))
                {
                    list = this.FilterByNameParameter(list, this.GetWildcard(Name));
                }

                WriteObject(list, true);
            }
            else
            {
                using (var udpClient = new UdpClient())
                {
                    int to = THREE;
                    if (_dynLib != null && _dynLib.ParameterHasValue(pName))
                    {
                        to = _dynLib.GetParameterValue <int>(pName) * THOUSAND;
                    }

                    udpClient.Client.ReceiveTimeout = to;
                    List <SqlInstanceResult> results = this.SqlBrowserQuery(Names, udpClient);
                    WriteObject(results, true);
                    this.UpdateProgress(0);
                }
            }
        }
Beispiel #3
0
        protected override void BeginProcessing()
        {
            base.BeginProcessing();

            if (_dynLib != null && _dynLib.ParameterHasValue("DefaultDatabase"))
            {
                _defDb = _dynLib.GetParameterValue <string>("DefaultDatabase");
            }
        }
Beispiel #4
0
        protected override void BeginProcessing()
        {
            base.BeginProcessing();
            _collation = !_dynLib.ParameterHasValue("Collation")
                ? SmoContext.Connection.Collation
                : _dynLib.GetParameterValue <string>("Collation");

            if (string.IsNullOrEmpty(this.DataFilePath))
            {
                this.DataFilePath = SmoDatabase.GetDefaultDatabasePath();
            }

            if (string.IsNullOrEmpty(this.LogFilePath))
            {
                this.LogFilePath = SmoDatabase.GetDefaultLogPath();
            }
        }
Beispiel #5
0
        protected override void ProcessRecord()
        {
            var smoServer = (SmoServer)SmoContext.Connection;

            if (_dynLib.ParameterHasValue(PROPERTIES))
            {
                string[] props = _dynLib.GetParameterValue <string[]>(PROPERTIES);
                if (props.Contains("*"))
                {
                    WriteWarning("Loading all properties can cause PowerShell to use large amounts of memory if enumerated.  Use caution.");
                    smoServer.LoadProperty(AllProps);
                }
                else
                {
                    smoServer.LoadProperty(props);
                }
            }
            WriteObject(smoServer, false);
        }
Beispiel #6
0
        protected override void ProcessRecord()
        {
            if (_server == null && this.InputObject != null)
            {
                _server = this.InputObject.Parent;
            }

            if (_server == null)
            {
                throw new SmoContextNotSetException();
            }

            if (!string.IsNullOrEmpty(this.LoginName) && base.GetLoginFromName(this.LoginName, out SmoLogin found))
            {
                this.InputObject = found;
            }

            if (this.MyInvocation.BoundParameters.ContainsKey("ProcessId"))
            {
                base.WriteObject(this.FindProcess(this.ProcessId));
            }

            else
            {
                SqlProcessCollection col = this.InputObject != null
                    ? this.FindProcess(this.InputObject)
                    : this.FindProcess();

                if (this.Status.HasValue)
                {
                    col = (SqlProcessCollection)col.FindAll(x => x.Status.HasValue && x.Status.Value == this.Status.Value);
                }

                switch (this.SortBy)
                {
                case "Id":
                {
                    if (_dynLib.ParameterHasValue("Ascending") && _dynLib.GetParameterValue <bool>("Ascending"))
                    {
                        col.SortBySpid(true);
                    }

                    else
                    {
                        col.SortBySpid(false);
                    }

                    break;
                }

                case "Login":
                    col.SortByLogin();
                    break;

                case "Program":
                    col.SortByProgram();
                    break;

                default:
                    col.SortBySpid(false);
                    break;
                }
                base.WriteObject(col, true);
            }
        }