2013-06-20

Provides methods that are used to create a pipeline of commands and invoke those commands either synchronously or asynchronously within a runspace. This class also provides access to the output streams that contain data that is generated when the commands are invoked. This class is primarily intended for host applications that programmatically use Windows PowerShell to perform tasks. This class is introduced in Windows PowerShell 2.0

 

csc /target:library/reference:.\System.Management.Automation.dll ps-2-1.cs

To retain these changes, you can create a Windows PowerShell profile and add the aliases, functions, and variables to the profiles. The profile is loaded every time that Windows PowerShell starts<http://technet.microsoft.com/en-us/library/bb613488.aspx>

 

 1 using System;
 2 using System.Management.Automation;
 3 using System.ComponentModel;
 4 using System.IO;
 5 [Cmdlet("Touch","File")]
 6     public class TouchFileCommand:PSCmdlet
 7     {
 8         private string path = null;
 9         [Parameter]
10         public string Path
11         {
12             get
13             {
14                 return path;
15             }
16             set
17             {
18                 path = value;
19             }
20         }
21         protected override void ProcessRecord()
22         {
23             if(File.Exists(path))
24             {
25                 File.SetLastWriteTime(path,DateTime.Now );
26             }
27         }
28     }

 

posted @ 2013-06-20 14:34  xtypeu  阅读(109)  评论(0编辑  收藏  举报