如何使用Powershell的Get-help

  初学Powershell必不可少的是学会使用其的帮助文档,这样可以更高效的让我们学会Powershell。
  下面就说说新手学习Powershell如何从Powershell中的帮助文档中获取更多信息吧。我已最常用的获取进程(Get-service)为例,给大家讲讲。
1.可更新的帮助
  当第一次使用帮助文档时,需要更新帮助文档(确保电脑网络是通的)。需要注意的要点是需要在管理员权限下打开Powershell,否则就会出现无法更新的情况。
  那么怎么更新帮助文档呢  管理员模式下打开Powershell,输入update-help(小技巧:输入过程中可以使用tab快捷键进行自动补全哦)。
PS C:\Windows\system32> Update-Help
  输入完成之后,敲击回车enter就可以自动更新了。
2.使用帮助文档找命令
  比如我要查看当前的的服务Service。但是我不知道命令是什么。于是就可以这样做。其中*是通配符,通配符是啥呢,就是可以代替一个不知道输入内容。
PS C:\Windows\system32> help *service*

Name                              Category  Module                    Synop
----                              --------  ------                    -----
Get-Service                       Cmdlet    Microsoft.PowerShell.M... Gets
New-Service                       Cmdlet    Microsoft.PowerShell.M... Creat
New-WebServiceProxy               Cmdlet    Microsoft.PowerShell.M... Creat
Restart-Service                   Cmdlet    Microsoft.PowerShell.M... Stops
Resume-Service                    Cmdlet    Microsoft.PowerShell.M... Resum
Set-Service                       Cmdlet    Microsoft.PowerShell.M... Start
Start-Service                     Cmdlet    Microsoft.PowerShell.M... Start
Stop-Service                      Cmdlet    Microsoft.PowerShell.M... Stops
Suspend-Service                   Cmdlet    Microsoft.PowerShell.M... Suspe
Get-NetFirewallServiceFilter      Function  NetSecurity               ...
Set-NetFirewallServiceFilter      Function  NetSecurity               ...
  然后就可以看到需要命令与Service有关。只有英文差不多的就可以看出来Get-service就是我们要中命令。但是现在还不确定的是这个命令是不是直接用就可以了。下面我们来说说怎么回去详细的使用方法。
3.获取详细的帮助
  上面我们已经知道get-service可以获取当前host上的服务。那么怎么确定就是这样呢,可以这样做。查看帮助文档里的例子。然后就可以看到详细的说明帮助啦。
PS C:\Windows\system32> help Get-Service -Examples

名称
    Get-Service

摘要
    Gets the services on a local or remote computer.

    Example 1: Get all services on the computer

    PS C:\>Get-Service


    This command gets all of the services on the computer. It behaves as though you typed `Get-Service *`. The default
    display shows the status, service name, and display name of each service.
    Example 2: Get services that begin with a search string

    PS C:\>Get-Service "wmi*"


    This command retrieves services with service names that begin with WMI (the acronym for Windows Management Instrume
    ntation).
    Example 3: Display services that include a search string

    PS C:\>Get-Service -Displayname "*network*"


    This command displays services with a display name that includes the word network. Searching the display name finds
     network-related services even when the service name does not include "Net", such as xmlprov, the Network Provision
    ing Service.
    Example 4: Get services that begin with a search string and an exclusion

    PS C:\>Get-Service -Name "win*" -Exclude "WinRM"


    These commands get only the services with service names that begin with win, except for the WinRM service.
    Example 5: Display services that are currently active

    PS C:\>Get-Service | Where-Object {$_.Status -eq "Running"}
  好啦,就到这吧。

                      愿每个人都是上帝眷顾的幸运儿
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

M_pengpeng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值