PowerShell 技能连载 - 创建 PowerShell 命令速查表(第 2 部分)

在前一个技能中,我们创建了 PowerShell 命令的速查表,在此提醒,这行代码将会创建网络命令的速查表(假设您有存取本例中 NetAdapter 模块的权限):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
PS> Get-Command -Module NetAdapter | Get-Help | Select-Object -Property Name, Synopsis
Name Synopsis
---- --------
Disable-NetAdapter Disables a network adapter.
Disable-NetAdapterBinding Disables a binding to a netw...
Disable-NetAdapterChecksumOffload Disables the selected checks...
Disable-NetAdapterEncapsulatedPacketTaskOffload Disables encapsulated packet...
Disable-NetAdapterIPsecOffload Disables IPsec offload on th...
Disable-NetAdapterLso Disables all LSO properties,...
Disable-NetAdapterPacketDirect ...
Disable-NetAdapterPowerManagement Disables specific power mana...
Disable-NetAdapterQos Disables QoS on a network ad...
Disable-NetAdapterRdma Disables RDMA on a network a...
Disable-NetAdapterRsc Disables RSC on a network ad...
Disable-NetAdapterRss Disables RSS on a network ad...
Disable-NetAdapterSriov Disables SR-IOV on a network...
Disable-NetAdapterVmq Disables the VMQ feature on ...
Enable-NetAdapter Enables a network adapter.
Enable-NetAdapterBinding Enables binding of a protoco...
Enable-NetAdapterChecksumOffload Enables checksum offloads on...
Enable-NetAdapterEncapsulatedPacketTaskOffload Enables encapsulated packet ...
Enable-NetAdapterIPsecOffload Enables IPsec offload on the...
Enable-NetAdapterLso Enables LSO properties, such...
Enable-NetAdapterPacketDirect ...
Enable-NetAdapterPowerManagement Enables specific power manag...
Enable-NetAdapterQos Enables QoS on the network a...
Enable-NetAdapterRdma Enables RDMA on a network ad...
Enable-NetAdapterRsc Enables RSC on a network ada...
Enable-NetAdapterRss Enables RSS on a network ada...
Enable-NetAdapterSriov Enables SR-IOV on a network ...
Enable-NetAdapterVmq Enables VMQ on a network ada...
Get-NetAdapter Gets the basic network adapt...
Get-NetAdapterAdvancedProperty Gets the advanced properties...
Get-NetAdapterBinding Gets a list of bindings for ...
Get-NetAdapterChecksumOffload Gets the various checksum of...
Get-NetAdapterEncapsulatedPacketTaskOffload Gets the network adapters th...
...

要让这个列表更有价值,让我们将它转换为 HTML 表格,这样您可以在浏览器中打开,并且打印:

1
2
3
4
5
6
7
8
9
10
11
12
$ModuleName = "NetAdapter"
$OutFile = "$env:temp\commands.html"
Get-Command -Module $moduleName |
Get-Help |
Select-Object -Property Name, Synopsis |
ConvertTo-Html |
Set-Content -Path $OutFile
Invoke-Item -Path $OutFile

运行这段代码后,几秒钟后您的缺省 WEB 浏览器将会打开一个包含速查表信息的页面。现在可以用浏览器的命令来打印它。这个页面不是十分美观,但满足了它的需求。

本文国际来源:Creating PowerShell Command Cheat Sheets (Part 2)

评论