This tool can be used alone and can completely replace Cmd.exe. For example, the following:
But it's much more than that, for example, we can easily get all the process names:
To take another look, here's an example of getting a list of services that are currently running. (Can be easily filtered by conditions):
In addition, PowerShell also supports customization, for example, many of Microsoft's products offer specialized PowerShell plug-ins (typically: SQL Server,sharepoint server, Exchange server, and so on). Through these special shell, can realize the management of the server. function is very powerful. For example, the following sqlps can view a database like a folder:
For example, the EMS (Exchange Managment Shell) in the following illustration can modify an address list:
Looks good, for more details on PowerShell, if you are interested, you can refer to Microsoft's documentation. Next to talk about another topic, PowerShell is so powerful, but after all, manual operation, can you call it in the program, and perform the relevant operations?
The answer is: yes. Here's a small example:
Add a reference. This assembly is in the C:\Program Files (x86) \reference assemblies\microsoft\windowspowershell\v1.0 directory:
Write the following simple code:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Management.Automation;
Using System.Management.Automation.Runspaces;
Using System.Diagnostics;
Namespace Powershellinvoker
{
Class Program
{
static void Main (string] args)
{
var runspace = Runspacefactory.createrunspace ();
Runspace. Open ();
var piple = runspace. Createpipeline ("get-process");
var result = Piple. Invoke (). Select (P => p.baseobject). Cast<process> ();
foreach (var item in result)
{
Console.WriteLine ("{0}\t{1}\t{2}",
Item. Id.tostring (). PadRight (30),
Item. Processname.padright (30),
Item. Threads.count);
}
Console.read ();
}
}
}
Yes, PowerShell is based on the. NET Framework's object operations.