PowerShell is the de facto standard for automation and administration on Windows systems. The central design mantra in PowerShell is Think-Type-Get. That is: Think what you want, Type it, and Get the results. Unfortunately this mantra doesn't always work - PowerShell combines concepts from other languages (Perl, Python, and VBScript for example) and borrows ideas from other platforms (like pipelining in Bash). This creates an experience that feels familiar, but fails to behave consistently with our experiences. This creates "gotchas." In this course, we will analyze some specific cases of PowerShell's strange behavior in order to better understand how and why PowerShell works the way it does.
Jim has spent over 17 years developing software for aerospace, education, and casinos. Since 2010 he has run Code Owls LLC, a company in Charlotte NC specializing in IT tooling and automation technologies. Jim is a PowerShell MVP and avid speaker.
Paths In this module, we'll be taking a look at PowerShell Gotchas that relate to ‘Working with Paths'. Now Paths are a huge part of PowerShell. In fact, 25% of the commands that shipped with PowerShell 2 accepted a Path Parameter. So at first glance, it might seem that you would encounter these Path Gotchas that we're going to be discussing about 25% of the time. However, this 25% of the command base in PowerShell 2 actually represents some of the most frequently used commands in PowerShell. You're likely to encounter these situations a lot more often than you think. In addition, we'll see that while PowerShell and Windows often agree on the interpretation of a Path String, there's going to be plenty of cases where they come up with very different conclusions about where that path leads.
Strings In this part of the course, we'll identify some of the PowerShell Gotchas you'll experience as you work with strings. Now before we begin, let me ask you a simple question -- What do the following technologies have in common? PowerShell, Apache, Perl, Chef, SQL, ---, SNMP, and DNS; What do all these technologies have in common? They all use STRINGS in some form or fashion to get their work done. The bird may be the word, but when it comes to automation, the string is king. Since strings are used so pervasively across the different technologies, you're likely to integrate with PowerShell, the Gotchas we'll discuss inside of this module are things you'll encounter on a regular basis.
Logic The common theme binding this set of Gotchas is Logic, or more appropriately, the apparent lack of Logic. Logic's pretty important in our industry. We use Logic to keep things happening in an orderly and expected sequence. Our experience is that logical statements tend to be immutable fact. For example, if I show you a logical sentence, ‘A EQUALS B IS FALSE', this not only tells you something about the values of A and B, but you walk in to the statement assuming that reversing the values of A and B doesn't change the result of the statement. ‘B EQUALS A' should be false, because ‘A EQUALS B IS FALSE'. As we're going to see in this module, inside of PowerShell, that's not always true, and as frustrating as these logical gotchas can be, once you understand what's happening under the covers, there's an inherent beauty inside of the way PowerShell is trying to help you out. Gertrude Stein wrote, "A rose is a rose is a rose", and then PowerShell came along and said, ‘nah, not always'.