Skip to main content

Posts

Showing posts from November, 2016

Describing Objects

With over 70 PowerShell classes under my belt, I have a good idea of where most IT Pros struggle when making the mind shift to the PowerShell world.  Objects is one of the concepts that take a bit of time to accept.  Even though everything in PowerShell is an object, we need to remember that objects have been in the realm of the developer for decades.  For IT Pros, this is a foreign concept that we must embrace.  Besides, objects make your scripting life so much easier. Over the course of the next 7 blog postings, we will examine the different components of an object and supply you with some simple code examples to help you understand them better. Object orientated programming was just a buzz word on the horizon when I graduated college with a degree in Computer Science in the late 90’s.  I was out in the real world as a Network Administrator as opposed to a programmer for many years.  Sure, I wrote some automation programs for myself, but they were not object based.  When Pow

How to Search Strings with [ and ] in Them

One of the more difficult aspects of teaching PowerShell is the PowerShell pipeline. After delivering over 70 PowerShell classes, I know this is the part to really slow down and take our time with.  I’ve been working on some code to help answer the question “What can you pipe to what without plowing through the objects and help files.”  Since this is a repetitive task for anybody who codes in PowerShell, I thought it would be fun to automate the process. While doing my R&D on this project, I discovered that to search for strings with ‘[‘ or ‘]’ cannot be done with the –Like comparison operator.  Take a look below. PS C:\> $String = "ABC[CDE]" PS C:\> $Sting -like "*[*" The specified wildcard character pattern is not valid: *[* At line:1 char:1 + $Sting -like "*[*" + ~~~~~~~~~~~~~~~~~~     + CategoryInfo          : NotSpecified: (:) [], WildcardPatternException     + FullyQualifiedErrorId : RuntimeException It turn

Speed Test with .NET vs PowerShell and 20,000 Leagues Under the Sea

I’ve given a presentation at PowerShell User Groups several times that involve quantifying how much money you save your organizations through PowerShell.  Of course my actual goal is to help IT Pros justify a bigger raise.  I’m working on some new coding practices to help speed up your code execution.  I’m actually developing this code for both my Advance PowerShell Toolmaking class and also as a topic to hopefully present at the PowerShell Europe Summit in 2017 (Keeping my fingers crossed).  Here is just one of 19 (and counting) ways that I have come up with to accelerate code execution. I’m looking at replacing PowerShell cmdlets with .NET objects.  This example below looks at replacing Get-Content with [System.IO.StreamReader].  I utilized a text file of one of my favorite books, 20,000 Leagues Under the Sea by Jules Verne. The results are in measurement of time called ticks.  This is because milliseconds were too big. [System.IO.StreamReader] vs. Get-Content ------------