PowerShell Topics I’m Ready to Stop Talking About

综合技术 2017-04-12

Part of me wants to know every bit of PowerShell there is. I know that’s true about me, so I don’t have much of an input filter. If the content is PowerShell-related, I’m interested.

When it comes to sharing, however, there’s clearly got to be a point at which I shouldn’t be talking about something. Here are a few items that I’ve spoken or taught about that I think are going to get pulled from my routine.

  1. The TRAP statement
  2. Obscure Operators
  3. Filters
  4. Tee-Object
  5. (bonus) Workflows

Let’s go through them one by one and see why. And yes, I know that I’m talking about them, but this should be the last time (and this time I mean it).

The TRAP statement

The trap statement is the error handling statement that made the cut for v1.0 of PowerShell. If you weren’t a PowerShell user at that time you probably haven’t ever used it, favoring TRY/CATCH/FINALLY.

Instead of being a block-structured statement like TRY, TRAP worked in a scope, and functioned like a VB ON ERROR GOTO. The rules for program flow after a TRAP statement (which I’ve long forgotten) made understanding code that used TRAP into….a trap.

The advice I have given students in the past is, “If you stumble upon some code that uses TRAP, look for other code.”

Obscure Operators

PowerShell has a lot of operators, and that’s a good thing. On the other hand, I’m not sure why I need to tell people about every single operator. Some of the operators, though, are obscure enough that I haven’t used them in any language more than a handful of times in the last thirty years. Candidates for expulsion (from discussion, not from the language) include:

  • -SHL, -SHR (I guess someone does bitwise shifting, but I haven’t ever needed this except in machine language)
  • *=, /=, %= (I can see what these do, but I don’t ever do much arithmetic so don’t find the need for these “shorthand” operators)

Filters

Filters are another PowerShell 1.0 topic. They are one of the ways to use the pipeline for input without using advanced functions and parameter attributes. They’re pretty slick, but are easily replaced with an advanced function with a process block. In the last 5 years, I’ve only seen filters used once (by Rob Campbell at a user group meeting).

Tee-Object

I generally consider the -Object cmdlets to be the backbone of PowerShell. They allow you to deal with pipeline objects “once-and-for-all” and not write a bunch of plumbing code in every function. For that reason, I like to talk about all of them. Tee-Object, however, might get sent to an appendix, because I don’t see anyone using it and don’t use it myself. This one might be changing as we see (being optimistic) people with more Linux backgrounds submitting PowerShell code. They use tee, right? I find that the -outvariable common parameter serves most of the need I would have for Tee-Object, so, it makes this list.

And finally,

Workflows

Workflows sound awesome. When you talk about workflows you get to use adjectives like “robust”, and “resilient”. And don’t get me wrong Foreach-Object -Parallel is pretty sweet.

On the other hand, writing PowerShell in the workflow-subset of PowerShell is tricky. Remembering what needs to be an inlinescript and how to use/access variables in each kind of block is not fun.

I haven’t ever used workflows for anything interesting, and have only heard a few examples of them being used by coworkers. Those examples could mostly be summed up by “I needed parallel”.

It won’t be hard for me to stop talking about workflows, as I’ve never really talked about them.

Before I get flamed because I included/excluded your favorite topic, these are just for me. If you like one of these, sell it! You might convince me to change my mind. Is there something that you think should fade away? Let me know what it is. I might be able to change your mind.

–Mike

责编内容by:PowerShell Station (源链)。感谢您的支持!

您可能感兴趣的

揭开PowerShell对象一致,ToString()返回值不同的神秘面纱... 上一篇文章中我们了解到ToString()可以大致地描述对象,作为对象的作者也可以决定通过ToString()的返回值,返回什么样的描述信息,但是到了Power...
Handling Permissions Changes With Powershell Drew Furgiuele has a process to store and then re-run rights grants on SQL ...
powershell脚本删除无效的快捷方式和空文件夹... 运行脚本如果不指定路径参数, 默认删除开始菜单的无效快捷方式和空文件夹, 删除空文件夹会有确认提示 param ( $dir ) ...
Diskpart and PowerShell – part4: Remove a partitio... So far you’ve seen how to create and modify partitions and volumes. Its now time...
Regular Expression PowerShell RegEx Regular Expression PowerShell RegEx Hello, Regular Expression is a great con...