1,导出至EXCEL

  1. $arr =New-Object System.Collections.ArrayList
  2. $i = 1
  3. $pstablelist = @();
  4. $array =get-user
  5. do
  6. {
  7. IF ($array[$i].RecipientType -eq "UserMailbox")
  8. {
  9.  
  10. $mbx=Get-CASMailbox $array[$i].name
  11. IF($mbx.OWAEnabled)
  12. {
  13. $arr.add("name:"+$array[$i].name+" title:"+$array[$i].title );
  14.  
  15. $table = @{"name"=$array[$i].name;"title"=$array[$i].title;};
  16.  
  17. $pstable = New-Object -TypeName PSObject -Prop $table;
  18.  
  19. $pstablelist += $pstable;
  20. }
  21. }
  22.  
  23. $i++;
  24.  
  25. }
  26. while ($i -lt $array.Length)
  27. $pstablelist | Export-Csv c:\test.csv -NoTypeInformation

2,

  1. $ob1 = "foo"
  2.  
  3. Try
  4. {
  5. $ErrorActionPreference1 = "stop"
  6. $ErrorActionPreference11 = "stop"
  7. $ErrorActionPreference122 = "stop"
  8. $ErrorActionPreference221 = "stop"
  9. $ob11= 11/0;
  10. }
  11. Catch [System.Management.Automation.PSArgumentException]
  12. {
  13. "invalid object"
  14. }
  15. Catch [System.Exception]
  16. {
  17. $_.Exception.Message;
  18. "caught a system exception"
  19. }
  20. Finally
  21. {
  22. "end of script"
  23. }

 3,过滤

Get-MessageTrackingLog|?{$_.sourcecontext -eq '*12*'}|fl

Get-MessageTrackingLog|?{$_.sourcecontext -like '*12*'}|fl

Operator Description Example Result

-eq

equals

$a = 5 ; $a -eq 4

False

-ne

not equal

$a = 5 ; $a -ne 4

True

-gt

greater than

$a = 5 ; $a -gt 4

True

-ge

greater than or equal to

$a = 5 ; $a -ge 5

True

-lt

less than

$a = 5 ; $a -lt 5

False

-le

less than or equal to

$a = 5 ; $a -le 5

True

-like

wildcard comparison

$a = "This is Text" ; $a -like "Text"

False

-notlike

wildcard comparison

$a = "This is Text" ; $a -notlike "Text"

True

-match

regular expression comparison

$a = "Text is Text" ; $a -match "Text"

True

-notmatch

regular expression comparison

$a = "This is Text" ; $a -notmatch "Text$"

False

http://blogs.technet.com/b/heyscriptingguy/archive/2009/05/06/how-can-i-use-the-if-statement-in-windows-powershell.aspx

5,
Search-MailboxAuditLog js1 -ShowDetails -ResultSize 111/Unlimited | Sort-Object ItemSubject|fl itemsubject,identity -First 30

6, get the  compressed folder\files in  the  path C:\folder by powershell

gci -r C:\folder\ | where {$_.attributes -match "compressed"} | foreach {  $_.fullname }

gci -r C:\folder\ | where {$_.attributes -match "enr"} | foreach {  $_.fullname }

http://serverfault.com/questions/452529/view-find-all-compressed-files-on-the-server

powershell samples的更多相关文章

  1. Google App Engine10年,支持更多你喜欢的编程语言

    2008年4月7日google推出Google App Engine(GAE),时间过得真快,10年过去了,2010年3月google退出中国,一转眼也过去7年了.早在2009年的时候GAE就在中国内 ...

  2. WIN10 使用POWERSHELL 设置单应用KIOSK模式(win10家庭版或企业版)

    win10 使用PowerShell 设置单应用kiosk模式 win10 家版或企业版PowerShellshell 启动器 v1Autologon.exe 注意事项 win10 家庭版或企业版. ...

  3. 在PowerShell中使用curl(Invoke-WebRequest)

    前言 习惯了windows的界面模式就很难转去命令行,甚至以命令行发家的git也涌现出各种界面tool.然而命令行真的会比界面快的多,如果你是一个码农. situation:接到需求分析bug,需要访 ...

  4. Windows 7上执行Cake 报错原因是Powershell 版本问题

    在Windows 7 SP1 电脑上执行Cake的的例子 http://cakebuild.net/docs/tutorials/getting-started ,运行./Build.ps1 报下面的 ...

  5. <译>通过PowerShell工具跨多台服务器执行SQL脚本

    有时候,当我们并没有合适的第三方工具(大部分需要付费)去管理多台数据库服务器,那么如何做最省力.省心呢?!Powershell一个强大的工具,可以很方便帮到我们处理日常的数据库维护工作 .简单的几步搞 ...

  6. 利用PowerShell复制SQLServer账户的所有权限

    问题 对于DBA或者其他运维人员来说授权一个账户的相同权限给另一个账户是一个很普通的任务.但是随着服务器.数据库.应用.使用人员地增加就变得很枯燥乏味又耗时费力的工作.那么有什么容易的办法来实现这个任 ...

  7. PowerShell 数组以及XML操作

    PowerShell基础 PowerShell数组操作 将字符串拆分成数据的操作 cls #原始字符串 $str = "abc,def,ghi,mon" #数据定义 #$StrAr ...

  8. linux下mono,powershell安装教程

    1简介 简单来说pash就是bash+powershell 2官网 https://github.com/Pash-Project/Pash 3下载fedora20---lxde桌面---32位版. ...

  9. Windows下PowerShell监控Keepalived

    一.背景 某数据库服务器为CentOS,想要监控Keepalived的VIP是否有问题,通过邮件进行报警,但这台机器不能上外网,现在只能在Windows下通过PowerShell来完成发邮件预警. 二 ...

随机推荐

  1. linux 用户、组,修改文件权限

    文件权限 -rwxrw-r‐-1 root root 1213 Feb 2 09:39 abc - 10个字符确定不同用户能对文件干什么 - 第一个字符代表文件(-).目录(d),链接(l) - 其余 ...

  2. fragment的一些bug

    自从Android3.0引入了Fragment之后,使用Activity去嵌套一些Fragment的做法也变得更加流行,这确实是 Fragment带来的一些优点,比如说:Fragment可以使你能够将 ...

  3. apache http client vs urlconnection

    Google has deprecated HttpClient Choose an HTTP Client Most network-connected Android apps use HTTP ...

  4. SVG 2D入门1 - SVG综述

    位图与矢量图 以前,浏览器中显示的图形,例如jpeg.gif等,都是位图,这些图像格式是基于光栅的.在光栅图像中,图像文件定义了图像中每个像素的颜色值.浏览器需要读取这些值并做出相应行动.这种图像的再 ...

  5. metaprogramming笔记

    动态多态与静态多态 动态多态:允许我们通过单个基类指针或引用处理多个派生类型的对象. 模板元编程中强调静态多态,允许不同类型的对象以同样的方式被操纵,只要它们支持某种共通的语法即可. 动态多态,连同& ...

  6. 嵌入式 -- WINKHUB 边信道攻击 (NAND Glitch)

    0x00 前言 随着物联网IOT的飞速发展,各类嵌入式设备, 路由器安全研究也越来越火. 但因为跟以往纯软件安全研究的要求不同, 这类研究往往需要结合相应的硬件知识. 很多朋友困惑如何开始, 甚至卡在 ...

  7. 【LeetCode OJ】Best Time to Buy and Sell Stock

    Problem Link: http://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock/ We solve this problem ...

  8. 【Android UI】 Shape详解

    在Android开发过程中,经常需要改变控件的默认样式, 那么通常会使用多个图片来解决.不过这种方式可能需要多个图片,比如一个按钮,需要点击时的式样图片,默认的式样图片. 这样就容易使apk变大. 那 ...

  9. 一个经典例子让你彻彻底底理解java回调机制

    转帖请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/17483273),请尊重他人的辛勤劳动成果,谢谢 所谓回调: ...

  10. 转载: SQL Server中的索引

    http://www.blogjava.net/wangdetian168/archive/2011/03/07/347192.html 1 SQL Server中的索引 索引是与表或视图关联的磁盘上 ...