日期:2014-05-17 浏览次数:20729 次
对 powershell 做下总结
?
?
?
启动 powershell #字符串操作 对象操作 "hello".Length #进程操作 PS C:\> notepad PS C:\> $process=get-process notepad PS C:\> $process.Kill() #默认对象操作 PS C:\> 40GB/650MB 63.0153846153846 #时间操作 PS C:\> [DateTime]"2009-12-5" - [DateTime]::Now Days : -58 Hours : -14 Minutes : -53 Seconds : -58 Milliseconds : -510 Ticks : -50648385105314 TotalDays : -58.6208160941134 TotalHours : -1406.89958625872 TotalMinutes : -84413.9751755233 TotalSeconds : -5064838.5105314 TotalMilliseconds : -5064838510.5314 #时间对象操作 PS C:\> $result = [DateTime]"2009-12-5" - [DateTime]::Now PS C:\> $result.TotalDays -58.6213450248299 #查询今天星期几 PS C:\Users\vv> $date=Get-Date PS C:\Users\vv> $date.DayOfWeek Monday #查找powershell命令中包含单词process的命令 PS C:\> Get-Command *process* CommandType Name Definition ----------- ---- ---------- Application api-ms-win-core-processenvir... C:\Windows\system32\api-ms-w... Application api-ms-win-core-processthrea... C:\Windows\system32\api-ms-w... Cmdlet Debug-Process Debug-Process [-Name] <Strin... Cmdlet Get-Process Get-Process [[-Name] <String... Application microsoft-windows-kernel-pro... C:\Windows\system32\microsof... Application qprocess.exe C:\Windows\system32\qprocess... Cmdlet Start-Process Start-Process [-FilePath] <S... Cmdlet Stop-Process Stop-Process [-Id] <Int32[]>... Cmdlet Wait-Process Wait-Process [-Name] <String... #检索donet中对象的属性和方法 PS C:\> "aaa" | Get-Member TypeName: System.String Name MemberType Definition ---- ---------- ---------- Clone Method System.Object Clone() CompareTo Method int CompareTo(System.Object value), i... Contains Method bool Contains(string value) CopyTo Method System.Void CopyTo(int sourceIndex, c... EndsWith Method bool EndsWith(string value), bool End... Equals Method bool Equals(System.Object obj), bool ... GetEnumerator Method System.CharEnumerator GetEnumerator() GetHashCode Method int GetHashCode() GetType Method type GetType() GetTypeCode Method System.TypeCode GetTypeCode() IndexOf Method int IndexOf(char value), int IndexOf(... IndexOfAny Method int IndexOfAny(char[] anyOf), int Ind... Insert Method string Insert(int startIndex, string ... IsNormalized Method bool IsNormalized(), bool IsNormalize... LastIndexOf Method int LastIndexOf(char value), int Last... LastIndexOfAny Method int LastIndexOfAny(char[] anyOf), int... ... #统计所有正在运行的进程的句柄数 PS C:\> $handleCount=0 PS C:\> foreach($process in Get-process) { $handleCount +=$process.Handles } PS C:\> $handleCount 23318 #直接调用donet对象,获取网页内容 PS C:\> $webClient = New-Object System.Net.WebClient PS C:\> $content = $webClient.DownloadString("http://www.baidu.com") PS C:\> $content.Substring(0,1000) <html><head><meta http-equiv=Content-Type content="text/html;charset=gb2312"><t itle>百度一下,你就知道 </title><style>body{margin:4px 0}p{margin:0;paddin g:0}img{border:0}td,p,#u{font-size:12px}#b,#u,#l td,a{font-family:arial}#kw{fon t:16px Verdana;height:1.78em;padding-top:2px}#b{height:30px;padding-top:4px}#b, #b a{colo