Learning note(4) for windows powershell Tips
来源:互联网 发布:阿里云服务器配置选择 编辑:程序博客网 时间:2024/05/16 05:03
- Windows PowerShell每周提示(10):在我们的数组里有什么?
1. 查找值
$arrColors = "blue", "red", "green", "yellow", "white", "pink", "orange", "turquoise"
$arrColors –contains "black" => 输出 FALSE
$arrColors -notcontains "violet" => 输出 True
2. 大小写敏感:执行大小写敏感检查通过使用-ccontains及-cnotcontains操作符
3. $arrColors –like "bl*" : 使用-like操作符及通配符(*)来检查数组中是否包含以字母bl开头的任意值.
4. 数组排序: $arrColors = $arrColors | Sort-Object
我们把我们的数组($arrColors)通过管道传递给Sort-Object cmdlet。当Sort-Object完成对数组内项目的排序时,然后我们将这个新的已排序的列表赋值回$arrColors
- Windows PowerShell每周提示(12):统计文本文件信息
1. 统计文本信息:
Get-Content c:/scripts/alice.txt | Measure-Object –word –line –character
Get-Content c:/scripts/alice.txt | Measure-Object –word –line –character -ignorewhitespace
2.对变量也适用:
$a = "This is a two-line value `n stored in a variable."
$a | Measure-Object –word –line -character
- Windows PowerShell每周提示(13):格式化日期和时间
1. 快速格式化
限定符
格式
样本输出
d
短日期
8/30/2007
D
长日期
Thursday, August 30, 2007
f
完整日期时间(长日期及短时间)
Thursday, August 30, 20
F
FullDateTimePattern(长日期长时间)
Thursday, August 30, 2007 11:19:59 AM
g
常规(短日期短时间)
8/30/2007 11:20 AM
G
常规(短日期长时间)
8/30/2007 11:20:24 AM
m, M
MonthDayPattern
August 30
o
Round-trip date/time pattern
[Text]
2007-08-30T11:18:49.0312500-07:00
RFC1123Pattern
Thu, 30 Aug 2007 11:21:36 GMT
s
SortableDateTimePattern (基于 ISO 8601) 使用当地时间
2007-08-30T11:20:36
t
短时间
11:20 AM
T
长时间
11:20:42 AM
u
UniversalSortableDateTimePattern 使用通用时间显示格式
2007-08-30 11:21:50Z
U
完整日期时间(长日期长时间)使用通用时间
Thursday, August 30, 2007 6:21:52 PM
y, Y
YearMonthPattern
August, 2007
Get-Date -format d
Get-Date -format D
2. 自定义格式化
限定符
描述
d. %d
月中的某一天。一位数的日期没有前导零。指定“%d”如果格式化样式没有同其它格式化样式组合在一起
dd
月中的某一天。一位数的日期有一个前导零
ddd
周中某天的缩写名称
dddd
周中某天的完整名称,在 DayNames 中定义
h, %h
12 小时制的小时。一位数的小时数没有前导零。指定“%h”如果格式化样式没有同其它格式化样式组合在一起
hh
12 小时制的小时。一位数的小时数有前导零。
H, %H
24 小时制的小时。一位数的小时数没有前导零。指定“%H”如果格式化样式没有同其它格式化样式组合在一起
HH
24 小时制的小时。一位数的小时数有前导零。
m, %m
分钟。一位数的分钟数没有前导零。指定“%m”如果格式化样式没有同其它格式化样式组合在一起
mm
分钟。一位数的分钟数有一个前导零。
M, %M
数字月份。一位数月份前没有前导零。指定“%M”如果格式化样式没有同其它格式化样式组合在一起
MM
数字月份。一位数月份前有前导零
MMM
月份的缩写名称,在AbbreviatedMonthNames中定义
MMMM
月份的完整名称,在MonthNames中定义
s, %s
秒。一位数的秒数没有前导零。指定“%s”如果格式化样式没有同其它格式化样式组合在一起
ss
秒。一位数的秒数有一个前导零。
t, %t
在 AMDesignator 或 PMDesignator 中定义的 AM/PM 指示项的第一个字符(如果存在)。指定“%t”如果格式化样式没有同其它格式化样式组合在一起
tt
在 AMDesignator 或 PMDesignator 中定义的 AM/PM 指示项(如果存在)。
y, %y
不包含纪元的年份。如果不包含纪元的年份小于 10,则显示不具有前导零的年份。指定“%y”如果格式化样式没有同其它格式化样式组合在一起
yy
不包含纪元的年份。如果不包含纪元的年份小于 10,则显示具有前导零的年份。
yyy
三位数年份。如果年份小于100,则显示具有前导零的年份。
yyyy
包括纪元的四位或五位数的年份(取决于所使用的日历)。对于不够四位数的年份,将使用前导零填充。泰国佛历和朝鲜历都有五位数年份;如果使用的是五位数的日历,选择“yyyy”模式的用户将会看到所有五位数,而且这五位数不会带前导零。例外情况:对于日本历和台湾日历,始终看起来都像用户选择的是“yy”方式。
%c
其中 c 是格式模式(如果单独使用)。也就是说,若要单独使用格式模式“d”、“f”、“F”、“h”、“m”、“s”、“t”、“y”、“z”、“H”或“M”,请指定“%d”、“%f”、“%F”、“%h”、“%m”、“%s”、“%t”、“%y”、“%z”、“%H”或“%M”。
如果格式模式与原义字符或其他格式模式合并,则可以省略“%”字符。
/c
其中 c 是任意字符。照原义显示字符。若要显示反斜杠字符,请使用“//”。
Get-Date -format M.d.yyyy => 7.19.2009
Get-Date -format “yyyy MMM d” => 2007 Aug 30
3. uformat
Get-Date -uformat %j //%j限定符返回是年中的第几天
Get-Date -uformat %V // %V返回是年中的第几周。注意V是大写的。
4. Get-Date cmdlet始终能被使用在任何日期上
Get-Date 3/13/2008 -uformat %j //2008年3月13日是一年中的第几天?
- Learning note(4) for windows powershell Tips
- Learning note(1) for Windows PowerShell Tips
- Learning note(2) for windows powershell Tips
- Learning note(3) for Windows powershell Tips
- Learning note(5) for windows powershell Tips
- Learning note(6) for windows powershell Tips
- Learning note(7) for windows powershell Tips
- Learning note(8) for windows powershell Tips
- PowerShell learning note
- Windows Azure Learning Note (4) - Updating
- Stady notes: Windows powershell tips
- Windows powershell tips:Conditional Operators
- Tips for learning ActionScript 3.0
- Windows Azure Learning Note (1)
- Windows Azure Learning Note (2)
- Windows Azure Learning Note (3)
- Windows Azure Learning Note (5)
- 【Deep Learning】笔记:Tips for deep learning
- 建站知识:PV、UV和IP各指什么
- hello world
- 基于Ajax的二级联动下拉菜单
- 多项目SVN权限管理
- Jsp+javascript打造二级级联下拉菜单
- Learning note(4) for windows powershell Tips
- 解决办法:服务器未能识别 HTTP 标头 SOAPAction 的值
- 软件架构设计思考
- 考虑
- 中国数字标牌、数字告示系统
- 解决了一个困扰了几个月的问题……令人郁闷……
- 基于jQuery的好友选择器V2.0
- [营养知识]43个不可不知的健康常识
- java开源框架集成常见错误之spring2.5中没有org.springframework.web.struts.DelegatingActionProxy ,使得Action不能注入到spring中