Regular Expression Magic in Powershell
I have been looking at regular expressions in Windows Powershell recently. Although it seems very complex, the power of regular expressions (regex) is worth the effort! Think about server naming conventions for example. It’s easy for a human to recognise a server name that begins with a location code and contains a status (Development, Test, Acceptance or Production) amongst other things. RegEx allows you to learn Powershell to recognise the same things.
The attached script contains a function that finds matches for a regular expresion and converts the named matches to object properties. Sounds complex? Take a look at this example for server names:
If you can create the regular expression, this function does the matching and objectizing. It requires no modification at all for working with regular expressions that match other kinds of things, because you name the matching groups inside the regex definition. Cool stuff!
Enjoy!
Hugo
No related posts.
Tags
Active Directory API bind order cleanup cluster CPU Custom Fields datastores description device management directory tree errors Event Log file name filter Fun function HA IT known issues License Server LUN multipath NIC objects Oneliner portgroups PowerCLI PowerShell profile recursive Registry Scripts security session share snapshots SQL Stat VI Toolkit VMware vSphere WMI WSUS ZenArchives
- July 2012
- July 2011
- February 2011
- January 2011
- December 2010
- May 2010
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008





