官术网_书友最值得收藏!

How does that work?

Knowing what commands you can execute is a big step, but it doesn't help much if you don't know how you can use them. Again, PowerShell is here to help you. To see a quick hint of how to use a cmdlet, write the cmdlet name followed by -?. The beginning of this output for Get-Service is shown as follows:

How does that work?

Even this brief help, which was truncated to fit on the page, shows a brief synopsis of the cmdlet and the syntax to call it, including the possible parameters and their types. The rest of the display shows a longer description of the cmdlet, a list of the related topics, and some instructions about getting more help about Get-Service:

How does that work?

In the Remarks section, we can see that there's a cmdlet called Get-Help (the second of the "big 3" cmdlets) that allows us to view more extensive help in PowerShell. The first type of extra help we can see is the examples. The example output begins with the name and synopsis of the cmdlet and is followed, in the case of Get-Service, by 11 examples that range from simple to complex. The help for each cmdlet is different, but in general you will find these examples to be a treasure trove providing an insight into not only how the cmdlets behave in isolation, but also in combination with other commands in real scenarios:

How does that work?

Also, mentioned in this are the ways to display more information about the cmdlet using the –Detailed or –Full switches with Get-Help. The –Detailed switch shows the examples as well as the basic descriptions of each parameter. The –Full switch adds sections on inputs, outputs, and detailed parameter information to the –Detailed output.

Tip

Using Get-Help for a cmdlet without specifying any other parameters gives the same output as using -? after the cmdlet name.

If you're running PowerShell 3.0 or above, instead of getting a complete help entry, you probably received a message like this:

How does that work?

This is because in PowerShell 3.0, the PowerShell team switched to the concept of update-able help. In order to deal with time constraints around shipping and the complexity of releasing updates to installed software, the help content for the PowerShell modules is now updated via a cmdlet called Update-Help. Using this mechanism, the team can revise, expand, and correct the help content on a continual basis, and users can be sure to have the most recent content at all times:

How does that work?

Tip

Update-Help requires an elevated session, so make sure that you start the PowerShell session as an administrator before trying to update your help content.

In addition to the help with individual cmdlets, PowerShell includes help content about all aspects of the PowerShell environment. These help topics are named beginning with about_ and can also be viewed with the Get-Help cmdlet. The list of topics can be retrieved using get-Help about_*:

How does that work?

Using measure-object, as we saw in a previous section, we can see that there are 124 topics listed in my installation:

How does that work?

These help topics are often extremely long and contain some of the best documentation on the working of PowerShell you will ever find. For that reason, I will end each chapter in this book with a list of help topics to read about the topics covered in the chapter.

In addition to reading the help content in the output area of the ISE and the text console, PowerShell 3.0 added a –ShowWindow switch to get-help that allows viewing in a separate window. All help content is shown in the window, but sections can be hidden using the settings button:

How does that work?
主站蜘蛛池模板: 同德县| 沽源县| 鹤山市| 高邑县| 鹤山市| 泌阳县| 大悟县| 宜阳县| 辽阳县| 塔城市| 四川省| 浦县| 阳城县| 长海县| 博兴县| 临泉县| 新民市| 龙井市| 陵水| 眉山市| 稷山县| 镇远县| 武山县| 米脂县| 丹巴县| 浮山县| 镇雄县| 桃园市| 祁东县| 双江| 乌鲁木齐县| 新丰县| 凌海市| 闸北区| 宁都县| 乐安县| 武宁县| 金坛市| 肇州县| 延津县| 盐池县|