《Learn Windows PowerShell in a Month of Lunches Third Edition》读书笔记——CHAPTER 3 Using the help system

Asking for help

function help pipes the help output to More . 这样的话每次可以看一整屏,需要继续看摁回车。

help is wappers around the core Get-Help cmdlet.

Get-Help Get-Content | More 等同于 Help Get-Content

NOTE: The More command won’t work in the ISE.
.

3.4 Using help to find commands

如果我们想要知道一些关于event log的命令,我们可以使用 help 来搜索有关命令:

Help *log*
Help *event*

3.5 Interpreting the help

3.5.1 Parameter sets and common parameters

SYNTAX
    Get-EventLog [-AsString] [-ComputerName <string[]>] [-List] [<Com
    monParameters>]
    Get-EventLog [-LogName] <string> [[-InstanceId] <Int64[]>] [-Afte
    r <DateTime>] [-AsBaseObject] [-Before <DateTime>] [-ComputerName
     <string[]>] [-EntryType <string[]>] [-Index <Int32[]>] [-Message
     <string>] [-Newest <int>] [-Source <string[]>] [-UserName <strin
    g[]>] [<CommonParameters>]

Get-EventLog 被列举两次暗示此命令支持两种参数集(parameter sets),我们可以使用任何一种,但是两者的参数不能混用。

3.5.2 Optional and mandatory parameters

[-ComputerName <string[]>] 意味着整个 -ComputerName 参数是可选的,因为其名字和值都在方括号内,我们可以不使用此参数。

[-LogName] <string> 表示此参数不能忽略,因为该参数的名字和值不在方括号内,但是名字 -LogName 可以忽略不写。

3.5.3 Positional parameters

利用帮助文档中参数出现的顺序,我们可以按照参数顺序来写其值,从而达到忽略参数的目的。

我们还可以使用 Help-full 参数来定位位置参数,比如:
Help Get-EventLog -full

我们也可以使用其 -ShowWindow 参数可视化查看,不过不适用于 non-Windows 操作系统。

3.5.4 Parameter values

值得注意的是,有些参数并没有输入值,比如说 [-AsString] ,这些参数被称为 switches
1. Switches are never positional; you always have to type the parameter name (or at least an abbreviated version of it).
2. Switches are always optional, which gives you the choice to use them or not.


其他的参数则要求有输入值,这些 输入值的类型 通常被包围在一对尖括号里。

常见的输入值的类型有:
1. String——当含有空格的时候,得加上引号(最好是单引号)
2. Int, Int32, or Int64
3. DateTime——字符串可以被解释为日期,取决于计算机的本地设置。比如在美国,日期通常像 10-10-2010 这样


有些值会有更多的方括号,比如:[-ComputerName <string[]>]
这里的 <string[]> 意味着参数可以接受一个数组、集合或者一系列字符串。当然,在这种情况下,单个的值也是合法的:
Get-EventLog Security -computer Server-R2

我们也可以提供多个值。最简单的方法是使用一个用逗号隔开的序列。PowerShell将所有用逗号隔开的序列当作一组值:
Get-EventLog Security -computer Server-R2,DC4,Files02

每个值都可以在引号内。但是,任何一个单独的含有空格的值都 必须 包含在引号内,下面这样是合法的:
Get-EventLog Security -computer 'Server-R2','Files02'

但是这样是错误的:
Get-EventLog Security -computer 'Server-R2,Files01'

另一种提供一系列的值的方法是将其输入到文件里,每个值一行,比如:

Server-R2
Files02
Files03
DC04
DC03

然后使用 Get-Content cmdlet去读取这个文件:
Get-EventLog Application -computer (Get-Content names.txt)
我们通过圆括号来改变命令执行顺序。

3.5.5 Finding command examples

我们通过 Help 命令的 -example 参数来查看例子,如 Help Get-EventLog -example

3.7 Accessing online help

使用 Help-online 参数来在线查看帮助,如Help Get-EventLog -online

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值