コード例 #1
0
        public override CommandResult Execute(CommandResult pipeIn)
        {
            // Obtain parameters
            string wmiNamespace = _arguments.Get <StringArgument>("Namespace").Value;
            string wmiQuery     = _arguments.Get <StringArgument>("Query").Value;
            string wmiClass     = _arguments.Get <StringArgument>("Class").Value;
            string wmiFilter    = _arguments.Get <StringArgument>("Filter").Value;

            // If no query is specified, assume a class is specified
            if (!wmiQuery.ToUpperInvariant().Contains("SELECT"))
            {
                wmiClass = wmiQuery;
            }

            if (wmiClass != null)
            {
                wmiQuery = string.Format("Select * From {0}", wmiClass);
            }
            if (wmiFilter != null)
            {
                wmiQuery += string.Format(" Where {0}", wmiFilter);
            }

            // Remote parameters
            string computerName = _arguments.Get <StringArgument>("ComputerName").Value;
            string username     = _arguments.Get <StringArgument>("Username").Value;
            string password     = _arguments.Get <StringArgument>("Password").Value;

            // Execute user provided WMI query and return results to pipeline
            _results = WmiHelper.ExecuteWmiQuery(wmiNamespace, wmiQuery, computerName, username, password);
            return(_results);
        }
コード例 #2
0
        public override CommandResult Execute(CommandResult pipeIn)
        {
            // Parameters
            string group = _arguments.Get <StringArgument>("Group").Value;
            string name  = _arguments.Get <StringArgument>("Name").Value;

            string hostname = System.Environment.MachineName;
            string query    = "Associators Of {{Win32_Group.Domain='{0}',Name='{1}'}} Where ResultClass = Win32_UserAccount";

            if (!string.IsNullOrEmpty(group))
            {
                query = string.Format(query, hostname, group);
            }
            else if (!string.IsNullOrEmpty(name))
            {
                query = string.Format(query, hostname, name);
            }
            else
            {
                throw new InvalidOperationException("-Group or -Name parameter needs to be provided");
            }

            _results = WmiHelper.ExecuteWmiQuery(query);

            return(_results);
        }
コード例 #3
0
        public override CommandResult Execute(CommandResult pipeIn)
        {
            string computerName = _arguments.Get <StringArgument>("ComputerName").Value;
            string username     = _arguments.Get <StringArgument>("Username").Value;
            string password     = _arguments.Get <StringArgument>("Password").Value;

            _results = WmiHelper.ExecuteWmiQuery(@"ROOT\CIMV2", "Select ProcessId, Name, CommandLine From Win32_Process", computerName, username, password);

            return(_results);
        }
コード例 #4
0
        public override CommandResult Execute(CommandResult pipeIn)
        {
            // Collect parameters for remote execution
            base.Execute();

            string allNameArguments = _arguments.Get <StringArgument>("Name").Value;

            string where = string.Empty;
            if (!string.IsNullOrEmpty(allNameArguments))
            {
                string[]      processNames = allNameArguments.Split(',');
                StringBuilder whereStr     = new StringBuilder(" Where (");

                bool first = true;
                foreach (string name in processNames)
                {
                    string newname = name;
                    if (!name.ToUpperInvariant().EndsWith(".EXE"))
                    {
                        newname = name + ".exe";
                    }

                    if (first)
                    {
                        whereStr.AppendFormat("(name = '{0}')", newname);
                        first = false;
                    }
                    else
                    {
                        whereStr.AppendFormat(" or (name = '{0}')", newname);
                    }
                }

                whereStr.Append(")");
                where = whereStr.ToString();
            }

            _results = WmiHelper.ExecuteWmiQuery("Select ProcessId, Name, CommandLine From Win32_Process" + where, computername, username, password);

            if (_results.Count == 0)
            {
                throw new NoPowerShellException(
                          string.Format("Cannot find a process with the name \"{0}\". Verify the process name and call the cmdlet again.", allNameArguments)
                          );
            }

            return(_results);
        }
コード例 #5
0
        public override CommandResult Execute(CommandResult pipeIn)
        {
            string allNameArguments = _arguments.Get <StringArgument>("Name").Value;

            string where = string.Empty;
            if (!string.IsNullOrEmpty(allNameArguments))
            {
                string[]      processNames = allNameArguments.Split(',');
                StringBuilder whereStr     = new StringBuilder(" Where (");

                bool first = true;
                foreach (string name in processNames)
                {
                    string newname = name;
                    if (!name.ToUpperInvariant().EndsWith(".EXE"))
                    {
                        newname = name + ".exe";
                    }

                    if (first)
                    {
                        whereStr.AppendFormat("(name = '{0}')", newname);
                        first = false;
                    }
                    else
                    {
                        whereStr.AppendFormat(" or (name = '{0}')", newname);
                    }
                }

                whereStr.Append(")");
                where = whereStr.ToString();
            }

            // Remote
            string computerName = _arguments.Get <StringArgument>("ComputerName").Value;
            string username     = _arguments.Get <StringArgument>("Username").Value;
            string password     = _arguments.Get <StringArgument>("Password").Value;

            _results = WmiHelper.ExecuteWmiQuery(@"ROOT\CIMV2", "Select ProcessId, Name, CommandLine From Win32_Process" + where, computerName, username, password);

            return(_results);
        }
コード例 #6
0
        public override CommandResult Execute(CommandResult pipeIn)
        {
            bool all = _arguments.Get <BoolArgument>("All").Value;

            string simpleSelect = "Description, IPAddress, DefaultIPGateway";
            string allSelect    = simpleSelect + ", DNSServerSearchOrder";
            string query        = "Select {0} From Win32_NetworkAdapterConfiguration {1}";

            if (all)
            {
                query = string.Format(query, allSelect, string.Empty);
            }
            else
            {
                query = string.Format(query, simpleSelect, "Where IPEnabled = 'True'");
            }

            _results = WmiHelper.ExecuteWmiQuery(query);

            return(_results);
        }
コード例 #7
0
        public override CommandResult Execute(CommandResult pipeIn)
        {
            // Collect parameters for remote execution
            base.Execute();

            CommandResult wmiHotfixes = WmiHelper.ExecuteWmiQuery("Select CSName,Description,HotFixID,InstalledBy,InstalledOn From Win32_QuickFixEngineering", computername, username, password);

            foreach (ResultRecord hotfix in wmiHotfixes)
            {
                _results.Add(
                    new ResultRecord()
                {
                    { "Source", hotfix["CSName"] },
                    { "Description", hotfix["Description"] },
                    { "HotFixID", hotfix["HotFixID"] },
                    { "InstalledBy", hotfix["InstalledBy"] },
                    { "InstalledOn", hotfix["InstalledOn"] }
                }
                    );
            }

            return(_results);
        }
コード例 #8
0
        public override CommandResult Execute(CommandResult pipeIn)
        {
            string name = _arguments.Get <StringArgument>("Name").Value;
            string sid  = _arguments.Get <StringArgument>("SID").Value;

            string query = "Select Name, Description, Disabled{0} From Win32_UserAccount Where LocalAccount='True'{1}";

            if (!string.IsNullOrEmpty(name))
            {
                query = string.Format(query, ", SID", string.Format(" And Name='{0}'", name));
            }
            else if (!string.IsNullOrEmpty(sid))
            {
                query = string.Format(query, ", SID", string.Format(" And SID='{0}'", sid));
            }
            else
            {
                query = string.Format(query, string.Empty, string.Empty);
            }

            _results = WmiHelper.ExecuteWmiQuery(query);

            return(_results);
        }
コード例 #9
0
        public override CommandResult Execute(CommandResult pipeIn)
        {
            bool simple = _arguments.Get <BoolArgument>("Simple").Value;

            ResultRecord wmiOS = WmiHelper.ExecuteWmiQuery("Select * From Win32_OperatingSystem")[0];
            ResultRecord wmiCS = WmiHelper.ExecuteWmiQuery("Select * From Win32_ComputerSystem")[0];

            // OS Version
            string strOsVersion = string.Format("{0} Build {1}",
                                                wmiOS["Version"],
                                                /* wmiInfo["CSDVersion"],*/ // TODO
                                                wmiOS["BuildNumber"]);

            // Original Install Date
            string sOrigInstallDate = null;
            Match  dateMatch        = MatchDate(wmiOS, "InstallDate");

            if (dateMatch != null)
            {
                sOrigInstallDate = string.Format("{0}-{1}-{2}, {3}:{4}:{5}",
                                                 dateMatch.Groups[3], dateMatch.Groups[2], dateMatch.Groups[1],
                                                 dateMatch.Groups[4], dateMatch.Groups[5], dateMatch.Groups[6]);
            }

            // System Boot Time
            string sSystemBootTime = null;

            dateMatch = MatchDate(wmiOS, "LastBootUpTime");
            if (dateMatch != null)
            {
                sSystemBootTime = string.Format("{0}-{1}-{2}, {3}:{4}:{5}",
                                                dateMatch.Groups[3], dateMatch.Groups[2], dateMatch.Groups[1],
                                                dateMatch.Groups[4], dateMatch.Groups[5], dateMatch.Groups[6]);
            }

            // Processors
            CommandResult wmiCPUs = WmiHelper.ExecuteWmiQuery("Select * From Win32_Processor");
            List <string> cpus    = new List <string>(wmiCPUs.Count);

            foreach (ResultRecord cpu in wmiCPUs)
            {
                cpus.Add(string.Format("{0} ~{1} Mhz", cpu["Description"], cpu["CurrentClockSpeed"]));
            }

            // Bios
            string       strBiosVersion = null;
            ResultRecord wmiBios        = WmiHelper.ExecuteWmiQuery("Select * From Win32_BIOS")[0];

            dateMatch = MatchDate(wmiBios, "ReleaseDate");
            if (dateMatch != null)
            {
                strBiosVersion = string.Format("{0} {1}, {2}-{3}-{4}",
                                               wmiBios["Manufacturer"], wmiBios["SMBIOSBIOSVersion"],
                                               dateMatch.Groups[3], dateMatch.Groups[2], dateMatch.Groups[1]);
            }

            // Hotfixes
            List <string> hotfixes = new List <string>()
            {
                "[unlisted]"
            };

            if (!simple)
            {
                CommandResult wmiHotfixes = WmiHelper.ExecuteWmiQuery("Select HotFixID From Win32_QuickFixEngineering");
                hotfixes = new List <string>(wmiHotfixes.Count);
                foreach (ResultRecord hotfix in wmiHotfixes)
                {
                    hotfixes.Add(hotfix["HotFixID"]);
                }
            }

            // Time zone
            int    timeZone  = Convert.ToInt32(wmiOS["CurrentTimeZone"]) / 60;
            string sTimeZone = string.Format("UTC{0}{1}", timeZone > 0 ? "+" : "-", timeZone);

            // Pagefile
            string sPageFile = WmiHelper.ExecuteWmiQuery("Select Name From Win32_PageFileUsage")[0]["Name"];

            // Summarize information
            _results.Add(
                new ResultRecord()
            {
                { "Host Name", wmiOS["CSName"] },
                { "OS Name", wmiOS["Caption"] },
                { "OS Version", strOsVersion },
                { "OS Manufacturer", wmiOS["Manufacturer"] },
                { "OS Build Type", wmiOS["BuildType"] },
                { "Registered Owner", wmiOS["RegisteredUser"] },
                { "Registered Organization", wmiOS["Organization"] },
                { "Product ID", wmiOS["SerialNumber"] },
                { "Original Install Date", sOrigInstallDate },
                { "System Boot Time", sSystemBootTime },
                { "System Manufacturer", wmiCS["Manufacturer"] },
                { "System Model", wmiCS["Model"] },
                { "System Type", wmiCS["SystemType"] },
                { "Processor(s)", string.Join(", ", cpus.ToArray()) },
                { "BIOS Version", strBiosVersion },
                { "Windows Directory", wmiOS["WindowsDirectory"] },
                { "System Directory", wmiOS["SystemDirectory"] },
                { "Boot Device", wmiOS["BootDevice"] },
                { "System Locale", wmiOS["OSLanguage"] },
                { "Input Locale", wmiOS["OSLanguage"] }, // TODO
                { "Time Zone", sTimeZone },              // TODO
                { "Total Physical Memory", wmiOS["TotalVisibleMemorySize"] },
                { "Available Physical Memory", wmiOS["FreePhysicalMemory"] },
                { "Virtual Memory: Max Size", wmiOS["TotalVirtualMemorySize"] },
                { "Virtual Memory: Available", wmiOS["FreeVirtualMemory"] },
                { "Virtual Memory: In Use", "[not implemented]" },     // TODO
                { "Page File Location(s)", sPageFile },
                { "Domain", wmiCS["Domain"] },
                { "Logon Server", Environment.GetEnvironmentVariable("LOGONSERVER") },
                { "Hotfix(s)", string.Join(", ", hotfixes.ToArray()) },
                { "Network Card(s)", "[not implemented]" },     // TODO
                { "Hyper-V Requirements", "[not implemented]" } // TODO
            }
                );

            return(_results);
        }
コード例 #10
0
        public override CommandResult Execute(CommandResult pipeIn)
        {
            _results = WmiHelper.ExecuteWmiQuery("Select Caption, Description, Destination, Mask, NextHop From Win32_IP4RouteTable");

            return(_results);
        }
コード例 #11
0
 public override CommandResult Execute(CommandResult pipeIn)
 {
     _results = WmiHelper.ExecuteWmiQuery("Select ProcessId, Name, CommandLine From Win32_Process");
     return(_results);
 }
コード例 #12
0
 public override CommandResult Execute(CommandResult pipeIn)
 {
     _results = WmiHelper.ExecuteWmiQuery(@"ROOT\Microsoft\Windows\SMB", "Select LocalPath,RemotePath From MSFT_SmbMapping");
     return(_results);
 }