PowerWF News, Tutorials, and more...

Get the latest tips and tricks directly from the PowerWF development team. Find out about new releases and upcoming features.


Seamless Automation

From the Desktop to the Data Center

The PowerWF family of products are easy enough for desktop and departmental automation, yet powerful and scalable enough for the Data Center. PowerWF compliments Opalis and other RBA solutions, lets you leverage your workforce and preserves your investment as your automation needs grow.


Special - 20% Discount


In conjunction with our recently announced Silver Award from Windows IT Magazine we would like to offer our customers an opportunity to save 20% off any Devfarm product purchase through the end of the year. This includes all PowerWF products as well as Devfarm's new PowerVI product!

PowerVI

vSphere Automation fueled by PowerShell


Designed for the VMware Administrator, PowerVI eases the automation of vSphere infrastructures. PowerVI includes over 100 PowerShell automation scripts that simplify everyday VMware administration tasks and PowerVI makes it easy to author new scripts.
December 6, 2011

Regular Replacements

As I mentioned before, Tobias at PowerShell.com has written a follow-up of his primer on using PowerShell regular expression, focusing on using regular expressions to slice and dice text.  He has added a third installment to the series that looks at using Regular Expressions to perform string replacements.

In Part 1, you lerned how Regular Expressions can extract useful information from noise text. In Part 2, we looked at using Regular Expressions to split text, yet another powerful technique to extract the pieces of information you may need. Today, we conclude our little excurse and use Regular Expressions to replace text. Fasten your seat belts, please!

Replacing Old Text With New Stuff

Replacing some information inside a text with some other information seems to be pretty straight-forward: simply use -replace and tell the operator which text you would like to replace with other text:

PS> ‘Hello World!’ -replace ‘World’, ‘PowerShell’
Hello PowerShell!

It is not obvious at first that -replace in reality takes a Regular Expression. You may notice accidentally when you try and use characters that have a special meaning, like here:

PS> ‘Hello.’ -replace ‘.’, ‘!’
!!!!!!

Huh? Well, “.” is a special RegEx placeholder and represents any character, so the result is right. If you must use special characters, they need to be escaped:

PS> ‘Hello.’ -replace ‘.’, ‘!’
Hello!

Remember the trick from our previous parts? If you aren’t sure which characters need to be escaped, ask PowerShell!

PS> [RegEx]::Escape(‘Hello.’)
Hello.


(read more)



November 16, 2011

Slicing and Dicing With PowerShell Regular Expressions

Tobias at PowerShell.com has written a follow-up of his primer on using PowerShell regular expression, focusing on using regular expressions to slice and dice text.

Regular Expressions can be your butchers’ knife to split text into pieces.

For example, to process a comma-separated list of values. Have a look:

‘comma,separated,list’ -split ‘,’

Here, the operator -split takes the text on its left side and chops the text up at each comma it finds. Yes, Regular Expressions do not need to be monsters. They can be very small. In this case, our Regular Expression simply is the comma - and represents a comma. It is - uh - a placeholder for - a comma. Easy enough.
… [onto more interesting cases] …
Let’s assume you have a long list of hexadecimal pairs and would like to convert that list back to decimals:

‘00AB1CFFAB1034’

To do that, you would somehow have to split after every second character and without consuming because you do not want to loose any information. Here is how you solve this puzzle:

PS> ‘00AB1CFFAB1034’ -split ‘(?<=\G[0-9a-f]{2})(?=.)’
00
AB
1C
FF
AB
10
34

Now you can pipe the pairs to Foreach-Object and convert them to decimals or bytes or whatever you may need:

PS> ‘00AB1CFFAB1034’ -split ‘(?<=\G[0-9a-f]{2})(?=.)’ |
  Foreach-Object { [System.Convert]::ToInt32($_, 16) }
0
171
28
255
171
16
52

(read more)



October 28, 2011

PowerShell Regular Expression Primer

I have always had a - love - hate - despise - relationship with irregular regular expressions.  PowerShell.com has a nice primer that can at least get you started on what will likely be one of the most fulfilling and frustrating relationships of your scripting life.

It starts with the basics of defining and explaining a regular expression pattern, and quickly shows you the power (and the frustrating nature) of working with them. The article also shows you several ways to do regular expressions within PowerShell.

The name of the article indicates that this may be part of a series.  If the follow-ups add a lot of value, I’ll let you know.