Klaus

Stories submitted by Klaus

Introducing Darth Enumerator, PowerShell TIE Fighter |e| Operator(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 1 month ago

Starting this project, I assumed that the distinction between an array and a Hashtable in PowerShell is the implementation of the IEnumerable interface. Now I know that there are two kinds of IEnumerables: There is one kind that PowerShell converts into Arrays before processing it in a pipeline for example an ArrayList. And another kind like a SortedList or a HashTable that get passed to the pipeline as scalar objects. My assumption was wrong and now there is some room for speculations. I wonder whether adding an extension method like ToArray() to the .NET Hashtable class, would let me pipe a Hashtable in PowerShell as Array of Dictionary Objects. read more...

add a comment |category: |Views: 7

tags: another

Tuning Click-Once deployment performance with VRTA and PowerShell(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 1 month ago

Some of our client applications get distributed using the Click-Once paradigm. One day we noticed that the time between the initial click on the download link in the browser and the complete initialization of the Click-Once desktop client application took much longer than a user would tolerate. We decided to debug the deployment of the application and fix the problem. We chose the Microsoft Netmon 3.2 and the VRTA (Visual Round Trip Analyzer) for the initial analysis. read more...

add a comment |category: |Views: 29

tags: another

Advanced file searches using PowerShell(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 2 months ago

As far as I can remember, PowerShell v1.0’s FileInfo object didn’t have a VersionInfo property. It has been added during the PowerShell 2.0 release. This property makes it much easier to search for files that belong to a specific Product or to a specific Vendor for example. This blog post demonstrates some file system searches based on the file version information. read more...

add a comment |category: |Views: 9

tags: another

Generating NUnit tests with PowerShell(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 2 months ago

The other day I needed to write NUnit unit tests to for a large number of method overloads. There were almost 100 methods that needed to be tested. The method signatures followed a well defined pattern. This didn’t look like much fun at first, but then I looked in my toolbox and I saw the smiling face of the PowerShell ISE shouting “Pick me! Pick me!”. About two hours later I had created a script that would parse the method signatures and generate NUnit test methods for each of the functions. read more...

add a comment |category: |Views: 29

tags: another

Getting Started: Scripting Incuity EMI models with PowerShell(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 3 months ago

The Incuity EMI (Enterprise Manufacturing Intelligence) software lets you connect to various plant historians, real time plant data servers and conventional relational database servers and access the underlying information through an unified entity model. The heart of the model is a powerful and elegant meta-repository. The setup of the data sources and the creation of the entity model can be automated by using an easy to use client .NET API. This article describes how to get started with this API and demonstrates the creation of a connector to the plant historian server from Wonderware using PowerShell. read more...

add a comment |category: |Views: 20

tags: another

When PowerShell hash table magic backfires(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 4 months ago

We just made it through the holidays and I finally found time to write about the most annoying thing in PowerShell: Hash table semi-automatic, which can easily result in some subtle bugs. And all of that, just because the hash tables don't behave as I would expect. I assumed hash tables to be implicitly sorted by the keys using the Sort-Object cmdlet and to always stay hash tables and not get converted into arrays of Dictionary Entries or even a single Dictionary entry when piped into a Where-Object cmdlet. To workaround these strange defects you need to apply some unnatural constructs and roll your own select statements. It just doesn't feel fair to make your children call GetEnumerator() before they try to find today's window on their Advents Calendar. read more...

add a comment |category: |Views: 20

tags: another

Dear PowerShell Santa...(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 5 months ago

PowerShell has a great potential, but it needs professional tool support in order for it to mature. The current solutions are far too amateur. Here is my list of PowerShell improvements for Santa Claus read more...

add a comment |category: |Views: 17

tags: another

One PowerShell Script to download PDC2008 Videos, Code and PowerPoints(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 5 months ago

Yes I did it. I downloaded all 65,563,667,714 bytes and saved them as 407 files on my nice new WD Passport hard drive that I brought home from the PDC2008. And, yes I did it the old fashioned manual way: Right-Click on link and Save-As. But you don't have to do it. In this blog post I provide the metadata of all the files I downloaded and a PowerShell script that will help you automating the download process. Besides the PDC content you also get to a treasure trove of PowerShell scripting techniques ranging from dynamically generating Regular Expressions to loading meta-data form XML and CSV files. read more...

add a comment |category: |Views: 229

tags: another

Meta-Programming with PowerShell and Regular Expressions(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 6 months ago

I am almost done with my biggest PowerShell scripting project so far. The last feature that I implemented was a flexible pattern matching facility. I wrote a procedure that would try to filter out a set of file names based on the first letters and the extensions of the file. The possible name prefixes and extensions would be provided by string arrays that could contain zero or more elements. The challenge as always with PowerShell is to understand its type conversion magic. One approach to this is to use baby steps while morphing the static regex string to a dynamically built regex string. This progression and the result is captured in this blog post. read more...

add a comment |category: |Views: 23

tags: another

Set-Content -Encoding parameter matters, if the content says so...(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 6 months ago

I use a simple PowerShell script to replace some of the URLs in my blog post's html source before I publish them to www.tellingmachine.com. In my case the posts are stored as XML files. Usually I use Windows Live Writer to write my posts. I publish the documents for test purposes frequently during the authoring to the VisualStudio 2008 development web server that runs locally on my machine. Once the post is ready to put online, I take the XML file, run the PowerShell script against it and then copy it to my production server. Occasionally the XML files refuse to open in Internet Explorer after I ran the script. It took me few minutes to figure out why. Here is the story! read more...

add a comment |category: |Views: 12

tags: another

What is the coolest thing on the planet? - PowerShell(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 7 months ago

Walter and I gave a presentation at the WonderWorld 2008 conference in Las Vegas last week. To get many people exited about our talk, we asked customers what they think the coolest thing on the planet is. They thought first that this is a trick question, but we didn't keep them in the dark for too long. The coolest thing on the planet is: PowerShell read more...

add a comment |category: |Views: 12

tags: another

Patching File System Trees with PowerShell(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 8 months ago

While working on a elaborate PowerShell script I needed to find a solution for the following problem: I wanted to do a string replace operation on a file system path name and have the resulting new string be reflected by the file system. For example the path name "C:\dogs\dog food\my favorites\hot dogs\Who let the dogs out.mp3" should be renamed by replacing "dog" with "cat". The resulting path name would be "C:\cats\cat food\my favorites\hot cats\Who let the cats out.mp3". Sounds easy, but how do I move the folders and files that are referred to in the path to their new locations? And even better, how can I do this recursively? This short blog post demonstrates two possible approaches. read more...

add a comment |category: |Views: 3

tags: another

Customization of PowerShell hash table merges(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 9 months ago

PowerShell provides the += operator to add one hash table to another hash table. By default this operation will result in an error, if both hash tables have at least one key that is common in both collections. In some cases you may want to have a more granular control. For example, you don't want to get an error, if not only the key, but also the value is common in both collections. read more...

add a comment |category: |Views: 12

tags: another

Finding missing and duplicate lines in text files using PowerShell(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 10 months ago

Every now and then I need to investigate bugs that get exposed because countable "things" are less or more than expected. In my special case I was dealing with an application that manages subscription handles to memory registers of programmable logic controllers (PLC). These programs are called Data Access Servers. Occasionally we get calls form customers reporting that the number of handles is less, or sometimes more than expected. The first step to debug this situation is to find out, which handles are missing or which ones are duplicates. This blog post describes how PowerShell's Compare-Object cmdlet makes this task, which used to be a pain in the "peep" now a piece of cake. read more...

add a comment |category: |Views: 4

tags: another

Extracting errors and warnings from a log file using PowerShell(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 10 months ago

This blog post shows a simple Powershell command that searches a log file for errors and warnings and adds the matched lines to either to the errors.txt file or to the warnings.txt files. It takes advantage of the most powerful operator in Powershell, which is the switch operator. In my example here I exported the log file from the Wonderware SMC logger. read more...

add a comment |category: |Views: 11

tags: another

Renaming a series of indexed files with Powershell(tellingmachine.com)

submitted by KlausKlaus(755) 3 years, 10 months ago

I love Powershell. I am only halfway through Bruce's book, but I am getting already a glimpse of its potential. I like especially the dynamic aspect of it. Creating and extending types on the fly is something that is quite exciting. Next I am looking to find a solution for my open issues with sorting hash tables. I think building a custom PSObject type with an integer NoteProperty and a NoteProperty that holds a FileInfo object might get me a few steps closer to solving the sorting challenge. read more...

add a comment |category: |Views: 4

tags: another