6月 262017
 

如下脚本,通过where cmdlet过滤出来netstat中已连接状态的连接:

可以发现, 使用字符串的split选项可以凑效,但是,使用字符串的split方法不能凑效; 因为split选项支持正则分隔符,split方法不支持正则分隔符,其实第二种写法是不对的。split方法只能按照单个字符分隔

参考: https://msdn.microsoft.com/en-us/library/System.String.Split(v=vs.110).aspx

统计每种tcp状态的数量:

 

其中,begin、end都很类似awk的用法

改进: 如何按照名字的升序进行输出呢:

注意这里sort的使用,需要使用 GetEnumerator(), 因为$arr 本身是一个大对象,本没有迭代为多个对象输出,是不会被sort的,所以需要$arr.GetEnumerator() ,然后输出给sort

tips: sort的 -Property 可以不写,直接 sort name (或)sort value

参考: https://blogs.technet.microsoft.com/heyscriptingguy/2014/09/28/weekend-scripter-sorting-powershell-hash-tables/

 

格式化输出:

 Posted by at 上午 11:40

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据