我们最近收到了一份Windows PowerShell 3.0 第一步(Windows PowerShell 3.0 First Steps),我决定接受审查它的挑战,主要有两个原因。第一个是我以前从未评论过一本书,我认为这是朝着这个方向的一个很好的练习。第二个原因是本书是为PowerShell 初学者(PowerShell beginner)编写的,而且——你猜对了——我是PowerShell 初学者(PowerShell beginner)。实际上,这有点言过其实,因为我以前从未使用过PowerShell,所以我认为这是学习新技能的好方法。事不宜迟,让我们深入了解这本书是否值得购买。
谁来教我 PowerShell?
Windows PowerShell 3.0 First Steps的作者是Ed Wilson。正如他的书的封面所告诉我们的那样,Ed 是微软(Microsoft)的高级顾问和著名的脚本专家(scripting expert)。鉴于他的技能,在为全球Microsoft客户和员工举办脚本研讨会时,他似乎是Microsoft的首选人员之一。(Microsoft)
Ed 还是Windows PowerShell 2.0 Best Practices和Microsoft VBScript Step by Step的作者,并且有他自己的TechNet 博客(TechNet blog),他在其中讨论了脚本。直到现在我才真正深入研究他的工作,但鉴于这些事实,我想说这家伙知道他在说什么,所以乍一看,我很乐意接受他关于学习PowerShell的建议。
透视事物
Ed Wilson为完全的初学者编写了这本书,并建议您从头到尾阅读它。这本书的写作语气很友好,很容易理解。作者在教你PowerShell(PowerShell)时没有使用技术性很强的行话,所以除非你刚买了一台电脑并且刚刚学习使用它,否则你在理解 Ed 所包含的课程和示例时应该没有任何问题。
为了更好地了解这本近 300 页的书的结构,以下是章节列表以及每个章节的预期内容:
-
第 1 章 - Windows PowerShell 3.0 概述- 第一章为您提供了关于(Chapter 1 - Overview of Windows PowerShell 3.0)PowerShell是什么的很好且易于理解的概述,还展示了Windows PowerShell 控制台(Windows PowerShell console)和Windows PowerShell 集成脚本环境(Windows PowerShell Integrated Scripting Environment)之间的一些差异,您将在稍后使用它在书中。您还将了解Powershell中使用的(Powershell)动词(verbs)和命名约定,以及一些直接影响PowerShell使用的基本安全方面。
-
第 2 章 - 使用 Windows PowerShell cmdlet(Chapter 2 - Using Windows PowerShell cmdlets) - 将本章视为(ABC)PowerShell的基础知识。Cmdlet(Cmdlets)是PowerShell的核心,如果您真的想学习使用它,您需要先掌握 cmdlet。幸运的是,Ed 在解释它们的作用和结构方面做得很好,并且很快给了你很多例子,你可以在自己的计算机上运行并自己测试它们以查看效果。此处给出的一些示例包括搜索 PowerShell 的帮助(Help)主题或使用Get-Command cmdlet 查找其他 cmdlet。本章以设置脚本执行(Script Execution) 策略的部分结束(Policy)(不用担心,您也将了解它的含义)并创建一个基本的Windows PowerShell 配置文件(Windows PowerShell profile)。
-
第 3 章 - 筛选、分组和排序(Chapter 3 - Filtering, grouping, and sorting)- PowerShell 非常适合让您深入了解不同类型的数据。本章首先向您介绍管道,然后教您如何对使用不同 cmdlet 获得的信息进行排序、分组或过滤。
-
第 4 章 - 格式化输出- 在(Chapter 4 - Formatting output)PowerShell 控制台(PowerShell console)中显示原始数据可能并不总是查看它的最佳方式。本书的第四章为您提供了如何在PowerShell(PowerShell)中创建表格并使用它以有组织的方式显示您需要的数据的动手演示。它还向您展示了如何使用输出网格(output grid),我敢打赌你们中的许多人都会喜欢这个功能。
-
第 5 章 - 存储输出(Chapter 5 - Storing output)- 一旦你掌握了从PowerShell中提取信息的窍门,Ed 将展示如何将这些信息存储在不同的工具中。他通过将信息存储在csv、txt和xml文件中来证明这一点。
-
第 6 章 - 利用 Windows PowerShell 提供程序(Chapter 6 - Leveraging Windows PowerShell providers)- 这是本书开始获得更多技术的地方。但是,嘿,这就是你来这里的目的,对吧?毕竟,我们谈论的是微软(Microsoft)操作系统中最强大的工具之一!本章解释什么是Windows PowerShell提供程序并仔细检查别名提供程序(Alias provider)、证书提供程序(Certificate provider)、环境提供程序(Environment provider)、文件系统提供程序(File System provider)、函数提供程序(Function provider)、注册表提供程序(Registry provider)和变量
提供者。现在冷静下来,深呼吸。当您仔细阅读和练习本书中的示例时,您将对PowerShell(PowerShell)有足够的了解,不会迷失在技术术语中。
-
第 7 章 - 使用 Windows PowerShell 远程处理(Chapter 7 - Using Windows PowerShell remoting)- 在我看来,这是本书最重要的章节之一。花点时间阅读它,如果您觉得需要,请再读第二或第三遍,因为这是展示PowerShell真正优势的地方。我什至会说,本节的内容就是将power这个词放在PowerShell中的原因。在这里,您将学习如何在远程计算机上运行命令、创建持久连接以及进行一些故障排除。
-
第 8 章 - 使用 WMI(Chapter 8 - Using WMI) - 本章详细介绍了Windows Management Instrumentation,自Windows NT 4.0以来, (Windows NT 4.0)Microsoft已将其包含在每个操作系统中(operating system)。是的,这很(that)重要。您将了解WMI类、提供程序和命名空间,并将通过以两种不同方式查询WMI来测试您的知识。(WMI)如果您熟悉SQL,那么您至少会对这两种方法中的一种感到宾至如归。
-
第 9 章 - 使用 CIM(Chapter 9 - Using CIM)通用信息模型(Information Model)( CIM ) 提供了一种从(CIM)Windows Management Instrumentation检索信息的有趣方法。Ed Wilson很好地解释了如何以及为什么在本地和远程使用此功能。
-
第 10 章 - 使用 Windows PowerShell ISE(Chapter 10 - Using the Windows PowerShell ISE) - Windows PowerShell ISE是一种更具交互性的方式,可以将PowerShell用于本书迄今为止讨论的几乎所有内容。您将学习如何使用环境、选项卡扩展功能(tab expansion feature)和输出窗格(Output pane)。本书还介绍了如何创建和删除ISE片段(是的,您还将了解这些片段是什么)。
-
第 11 章 - 使用 Windows PowerShell 脚本(Chapter 11 - Using Windows PowerShell scripts)- PowerShell为(PowerShell)网络管理(network management and administration)提供了大量选项。如果您是IT 管理员(IT administrator),您很可能会在日常任务中遇到反复出现的需求,这可以通过编写自己的脚本并从PowerShell运行来简化。虽然熟悉VBScript或任何其他脚本或编程语言(scripting or programming language)对理解本章很有用,我不认为它是强制性的。Ed 为初学者写了这本书,即使你还没有写过一行代码,也不难理解本章中举例说明的脚本。本章介绍了编写脚本的一些原因,向您展示如何运行它们,如何设置脚本执行策略,并教(execution policy and teaches)您有关变量和不同语言语句的知识。
-
第 12 章 - 使用函数- 在编写(Chapter 12 - Working with functions)PowerShell脚本时,函数是主要的编程元素。(programming element)本章首先介绍函数及其用法,然后解释如何使用参数进行输入。它还包括两个使用函数的特殊场景。
-
第 13 章 - 调试脚本(Chapter 13 - Debugging scripts)- 有句话类似于“最好的调试就是不调试”。当然,这在现实生活中很少发生。本章将带您了解脚本调试(script debugging)及其重要性、设置、列出、启用和禁用PowerShell脚本中的断点。
-
第 14 章 - 处理错误(Chapter 14 - Handling errors)- Ed Wilson优雅地结束了PowerShell课程,其中有一章专门介绍错误处理(error handling)。本章从一个关于缺失参数的好方法开始,然后继续教你限制选择和回顾如何处理缺失的权利。您还将学习结构化错误处理(error handling)。
本书包括两个附录部分,一个包含PowerShell FAQ,另一个以友好易懂的方式解释PowerShell 3.0编码约定,以便您在脚本可读性和维护(script readability and maintenance)方面学习一些最佳实践。
这就是它的工作原理......但这就是为什么
Ed 的教学风格(teaching style)的一大优点是他解释了为什么你需要以某种方式做事的方法,而不是使用猴子看,猴子做(monkey see, monkey do)的方法。每章都以简单的解释和手头问题的概述开始。然后它会推进到更具体的任务,同时也让你了解为什么需要这样做和那样做。作为一本面向初学者的书,我只能称赞这种方法,并希望(approach and hope)在尽可能多的书中看到它,尤其是技术类的。
每章都以它所包含的信息的摘要结尾,作为总结和记忆复习(memory refresher),以便您更好地理解和记住这些信息。
它对我有帮助吗?
简短的回答:是的!
作者采用了一个相当复杂的主题和Windows(Windows)中包含的最复杂的工具之一,并以一种既容易理解又有趣到足以让您着迷的方式对其进行了解释。我以前从未使用过PowerShell ,但在阅读本书之后,我可以肯定地说,我对(PowerShell)PowerShell是什么、它是如何工作的以及谁最能从它的使用中受益有了基本的了解。我没有过多地编写脚本,但这肯定是我们很快将在7 Tutorials中介绍的主题,而Ed Wilson的书将成为我们的圣经(Bible)。
判决
虽然熟悉Ed Wilson风格的人肯定会喜欢Windows PowerShell 3.0 第一步(Windows PowerShell 3.0 First Steps),但对于完全的初学者我也可以这么说。概念和示例得到了很好的解释,并且您在每章中都会获得一些实际的、自己动手的经验,这对学习很有帮助。虽然本书为新手提供了使用PowerShell(PowerShell)的一个很好的起点,但更有用的脚本编写者或 IT 管理员可能也会发现它也很有用,尤其是脚本章节和编码约定附录。鉴于这本书基本上向您展示了您无需成为计算机专家(computer expert)即可学习如何编写脚本以及自动化或管理网络任务(automate or manage network tasks),我强烈推荐给PowerShell的新手。
Book Review - Windows PowerShell 3.0 First Steps, by Ed Wilson
We recеntly received a copy of Windows PowerShell 3.0 First Steps and I decided to take on the challenge of reviewing it, mainly for two reasons. The first one is that I have never reviewed a book before and I saw it as a great exercise in this direction. The second reason is the fact that this book is written with PowerShell beginners in mind and - you guessed it - I'm a PowerShell beginner. Actually, that would be an overstatement, since I have never used PowerShell before, so I considered it a great way to get to learn a new skill. Without further ado, let's dive in and see if this book is worth buying.
Who's Going To Teach Me PowerShell?
The author of Windows PowerShell 3.0 First Steps is Ed Wilson. As the cover of his book informs us, Ed is a senior consultant at Microsoft and a well-known scripting expert. Given his skills, he seems to be one of Microsoft's go-to guys when it comes to presenting scripting workshops to Microsoft customers and employees around the globe.
Ed is also the author of Windows PowerShell 2.0 Best Practices, Microsoft VBScript Step by Step, and has his own TechNet blog on which he talks about scripting. I didn't really dig into his work until now, but given these facts I'd say the guy knows what he's talking about so, at the first glance, I would happily take his advice on learning PowerShell.
Putting Things Into Perspective
Ed Wilson wrote this book for complete beginners and advises you to read it from cover to cover. The tone in which this book is written is a friendly one, very easy to understand. The author doesn't use a highly technical jargon while teaching you PowerShell, so unless you have just bought a computer and are just learning to use it, you should not have any problem understanding the lessons and the examples that Ed included.
To get a better overview of how this almost 300 pages book is structured, here's a list of the chapters and what to expect in each one:
-
Chapter 1 - Overview of Windows PowerShell 3.0 - This first chapter gives you a very good and comprehensible overview of what PowerShell is and also shows some of the differences between the Windows PowerShell console and the Windows PowerShell Integrated Scripting Environment, which you will be using later on in the book. You also learn about the verbs and naming conventions used in Powershell as well as a few basic security aspects that directly impact the usage of PowerShell.
-
Chapter 2 - Using Windows PowerShell cmdlets - Consider this chapter the ABC of PowerShell. Cmdlets are the heart of PowerShell and if you really want to learn to use it, you'll need to master cmdlets first. Fortunately, Ed does a great job at explaining both their role and their structure, and quickly gives you lots of examples that you can run on your own computer and test them yourself to see the effect. Some of the examples given here include searching the Help topics of PowerShell or using the Get-Command cmdlet to find other cmdlets. The chapter ends with sections on setting up a Script Execution Policy (don't worry, you'll learn what that is as well) and creating a basic Windows PowerShell profile.
-
Chapter 3 - Filtering, grouping, and sorting - PowerShell is great at giving you thorough insight into different types of data. This chapter starts by taking you through an introduction to the pipeline and goes on by teaching you how to sort, group or filter the information you get from using different cmdlets.
-
Chapter 4 - Formatting output - Displaying raw data in the PowerShell console might not always be the best way to view it. The fourth chapter of the book gives you a hands-on demonstration of how to create a table in PowerShell and use it to display the data you need in an organized fashion. It also shows you how to use the output grid, a feature that I bet many of you will love.
-
Chapter 5 - Storing output - Once you get the hang of pulling information from PowerShell, Ed shows how to store that information in different tools. He demonstrates this by storing information in csv, txt and xml files.
-
Chapter 6 - Leveraging Windows PowerShell providers - This is where the book starts to get more technical. But hey, that's what you here for, right? After all, we are talking about one of the most powerful tools you will find in Microsoft's operating systems! This chapter explains what Windows PowerShell providers are and carefully examines the Alias provider, Certificate provider, Environment provider, File System provider, Function provider, Registry provider, and Variable
provider. Now calm down and take a deep breath. By the time you get here while carefully reading and practicing the examples shown in the book, you'll have a decent enough understanding of PowerShell to not get lost in technical terms.
-
Chapter 7 - Using Windows PowerShell remoting - In my opinion this is one of the most important chapters of the book. Take your time while reading it and give it a second or third read if you feel that you need to, because this is where the real strength of PowerShell is shown. I would go as far as to say that the contents of this section is what puts the word power in PowerShell. Here you'll learn how to run commands on a remote computer, create persistent connections and also do some troubleshooting.
-
Chapter 8 - Using WMI - This chapter goes into detail regarding Windows Management Instrumentation, which Microsoft has included in every operating system since Windows NT 4.0. Yes, it's that important. You will learn about WMI classes, providers and namespaces and will test your knowledge through querying WMI in two different ways. If you're familiar with SQL you'll feel right at home with at least one of the two methods.
-
Chapter 9 - Using CIM - Common Information Model (CIM) provides an interesting way to retrieve information from Windows Management Instrumentation. Ed Wilson does a good job explaining how and why to use this feature, both locally and remotely.
-
Chapter 10 - Using the Windows PowerShell ISE - The Windows PowerShell ISE is a more interactive way of using PowerShell for pretty much everything that the books has discussed so far. You will learn how to use the environment, the tab expansion feature and the Output pane. The book also covers how to create and remove ISE snippets (yes, you will learn what these are as well).
-
Chapter 11 - Using Windows PowerShell scripts - PowerShell offers a great deal of options for network management and administration. If you're an IT administrator, you will most likely encounter recurring needs in your daily tasks, that can be simplifies by writing your own scripts and running them from PowerShell. While some familiarity with VBScript or any other scripting or programming language would be of use in understanding this chapter, I wouldn't call it mandatory. Ed wrote this book for beginners and it's not hard to understand the scripts exemplified in this chapter even if you haven't written a line of code yet. The chapter presents some reasons to write scripts, shows you how to run them, how to set the script execution policy and teaches you about variables and different language statements.
-
Chapter 12 - Working with functions - Functions are the primary programming element when it comes to writing PowerShell scripts. The chapter begins with an introduction to functions and their usage and goes on explaining how to use parameters for input. It also includes two special scenarios for using functions.
-
Chapter 13 - Debugging scripts - There's a saying that goes something like "The best debugging is no debugging.". Of course, that rarely happens in real life. This chapter will take you through script debugging and its importance, setting, listing, enabling and disabling breakpoints in PowerShell scripts.
-
Chapter 14 - Handling errors - Ed Wilson gracefully concludes the PowerShell lessons with a chapter dedicated to error handling. The chapter begins with a good approach on missing parameters and goes on teaching you about limiting choices and reviewing how to handle missing rights. You also learn structured error handling.
The book includes two appendix sections, one containing a PowerShell FAQ and the other one explaining PowerShell 3.0 coding conventions in a friendly and understandable manner, so that you also learn some best practices in terms of script readability and maintenance.
That's How That Works... But Here's Why
A great thing about Ed's teaching style is his approach to explaining the reason why you need to do things a certain way and not using a monkey see, monkey do approach. Each chapter starts with simple explanations and an overview of the matter at hand. Then it advances to more specific tasks while also giving you an insight of why you need to do this and that. Being a beginner oriented book, I can only praise this approach and hope to see it in as many books as possible, especially technical ones.
Each chapter ends with a summary of the information it contains, serving as a wrap-up and a memory refresher for you to better understand and keep the information in mind.
Did It Help Me?
The short answer: Yes!
The author takes a fairly complex subject and one of the most complex tools that have ever been included in Windows and explains it in a way that's both easy to understand and interesting enough to keep you hooked. I have never used PowerShell before but, after reading the book, I can safely say that I have a basic understanding of what PowerShell is, how it works and who would best benefit from its usage. I didn't get into too much scripting, but this will definitely be a topic we will soon cover here, at 7 Tutorials, and Ed Wilson's book will be our Bible while doing that.
The Verdict
While those of you familiar with Ed Wilson's style will most definitely enjoy Windows PowerShell 3.0 First Steps, I could say the same for complete beginners. The concepts and examples are very well explained and you get some practical, do-it-yourself experience in each chapter, which can only be great for learning. While the book offers newcomers a great starting point in using PowerShell, more useful scripters or IT administrators might find it useful as well, especially the scripting chapters and the coding conventions appendix. Given that this is a book that basically shows you that you don't need to be a computer expert to be able to learn how to write scripts and automate or manage network tasks, I would highly recommend it for a newcomer to PowerShell.