powershell samples
1,导出至EXCEL
$arr =New-Object System.Collections.ArrayList
$i = 1
$pstablelist = @();
$array =get-user
do
{
IF ($array[$i].RecipientType -eq "UserMailbox")
{
$mbx=Get-CASMailbox $array[$i].name
IF($mbx.OWAEnabled)
{
$arr.add("name:"+$array[$i].name+" title:"+$array[$i].title );
$table = @{"name"=$array[$i].name;"title"=$array[$i].title;};
$pstable = New-Object -TypeName PSObject -Prop $table;
$pstablelist += $pstable;
}
}
$i++;
}
while ($i -lt $array.Length)
$pstablelist | Export-Csv c:\test.csv -NoTypeInformation
2,
$ob1 = "foo"
Try
{
$ErrorActionPreference1 = "stop"
$ErrorActionPreference11 = "stop"
$ErrorActionPreference122 = "stop"
$ErrorActionPreference221 = "stop"
$ob11= 11/0;
}
Catch [System.Management.Automation.PSArgumentException]
{
"invalid object"
}
Catch [System.Exception]
{
$_.Exception.Message;
"caught a system exception"
}
Finally
{
"end of script"
}
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 |
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的更多相关文章
- Google App Engine10年,支持更多你喜欢的编程语言
2008年4月7日google推出Google App Engine(GAE),时间过得真快,10年过去了,2010年3月google退出中国,一转眼也过去7年了.早在2009年的时候GAE就在中国内 ...
- WIN10 使用POWERSHELL 设置单应用KIOSK模式(win10家庭版或企业版)
win10 使用PowerShell 设置单应用kiosk模式 win10 家版或企业版PowerShellshell 启动器 v1Autologon.exe 注意事项 win10 家庭版或企业版. ...
- 在PowerShell中使用curl(Invoke-WebRequest)
前言 习惯了windows的界面模式就很难转去命令行,甚至以命令行发家的git也涌现出各种界面tool.然而命令行真的会比界面快的多,如果你是一个码农. situation:接到需求分析bug,需要访 ...
- Windows 7上执行Cake 报错原因是Powershell 版本问题
在Windows 7 SP1 电脑上执行Cake的的例子 http://cakebuild.net/docs/tutorials/getting-started ,运行./Build.ps1 报下面的 ...
- <译>通过PowerShell工具跨多台服务器执行SQL脚本
有时候,当我们并没有合适的第三方工具(大部分需要付费)去管理多台数据库服务器,那么如何做最省力.省心呢?!Powershell一个强大的工具,可以很方便帮到我们处理日常的数据库维护工作 .简单的几步搞 ...
- 利用PowerShell复制SQLServer账户的所有权限
问题 对于DBA或者其他运维人员来说授权一个账户的相同权限给另一个账户是一个很普通的任务.但是随着服务器.数据库.应用.使用人员地增加就变得很枯燥乏味又耗时费力的工作.那么有什么容易的办法来实现这个任 ...
- PowerShell 数组以及XML操作
PowerShell基础 PowerShell数组操作 将字符串拆分成数据的操作 cls #原始字符串 $str = "abc,def,ghi,mon" #数据定义 #$StrAr ...
- linux下mono,powershell安装教程
1简介 简单来说pash就是bash+powershell 2官网 https://github.com/Pash-Project/Pash 3下载fedora20---lxde桌面---32位版. ...
- Windows下PowerShell监控Keepalived
一.背景 某数据库服务器为CentOS,想要监控Keepalived的VIP是否有问题,通过邮件进行报警,但这台机器不能上外网,现在只能在Windows下通过PowerShell来完成发邮件预警. 二 ...
随机推荐
- JS内置对象
字符串对象 <script> //字符串对象 var str = "Hello worldlsgjlsjg"; document.write('string.lengt ...
- <转>thinkphp的各种内部函数 D()、F()、S()、C()、L()、A()、I()详解
D.F.S.C.L.A.I 他们都在functions.php这个文件家下面我分别说明一下他们的功能 D() 加载Model类M() 加载Model类 A() 加载Action类L() 获取语言定义C ...
- URAL 1306 Sequence Median(优先队列)
题意:求一串数字里的中位数.内存为1M.每个数范围是0到2的31次方-1. 思路:很容易想到把数字全部读入,然后排序,但是会超内存.用计数排序但是数又太大.由于我们只需要第n/2.n/2+1大(n为偶 ...
- 使用 VisualVM 进行性能分析及调优
VisualVM 是一款免费的性能分析工具.它通过 jvmstat.JMX.SA(Serviceability Agent)以及 Attach API 等多种方式从程序运行时获得实时数据,从而进行动态 ...
- Python学习路程day6
shelve 模块 shelve模块是一个简单的k,v将内存数据通过文件持久化的模块,可以持久化任何pickle可支持的python数据格式 import shelve d = shelve.open ...
- 控制台应用程序中Main函数的args参数
在VS中添加参数 菜单 项目 -- 你的项目属性 -- 调试 -- 启动选项 -- 命令行参数 参数之间用空格分隔开就可以了,如果参数有空格,以双引号风格
- 将byte[]数组数据转换为图片用于预览显示
假如服务器返回给你的图片信息是byte[] 然后你需要将起转换成图片显示到你的view中去: 按以下的步骤 1.将获取的byte数组保存 假如为temp[]; 2.将temp[]转化为bitmap,你 ...
- Android布局居中的几种做法
Android的布局文件中,如果想让一个组件(布局或View)居中显示在另一个布局(组件)中,可以由这么几种做法: android:layout_gravity android:gravity and ...
- POJ2449 (k短路)
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> # ...
- LCA(RMQ)
; xh=; ..lx*] of longint; lt,dfn,fr,dep:..lx] of longint; f:..lx*,..xh] of longint; vis:..lx] of boo ...