About Bartek Bielawski

IT Specialist. PowerShell MVP with great interest in WMI and Active Directory. Blogger, speaker, author.

Quick tip: reversed regex.

When working with regular expressions in PowerShell to check if certain string matches a pattern we can use it in both directions: to match or not match it (with –match and –notmatch operators). That’s very handy and it saves us a lot of time, because we don’t have to come up with regular expression that would do it for us. But there are certain situations where operators are not used.

Continue reading

Case-insensitive Select-Xml

Internet-xmlPowerShell is not case sensitive (most of the time). There are two situation when it is: you explicitly request it (e.g. using operators like –cmatch) or we depend on something where there is no easy way to turn it off. Select-Xml is using XPath and falls in the second category. Whenever I need to query large XML file I prefer to start with more general queries, and there is very few things more frustrating than being forced to remember case of e.g. attribute names. There are two options to go about it.

First of all we can do it easy way: change case of the whole string that defines XML, and be sure, that everything is either lower or upper case. Problem with this approach is the fact, that result we get back is different from original, and we are bit “stuck” with “broken” XML.

Second option is to use XPath own tools to get similar results, and has advantage of getting “proper” XML data back. Using Select-Xml also enables modifying XML and saving under different name.

Continue reading

Quick tip: human-readable LDAP filter

Whenever I work with Active Directory and I want to use pretty complex LDAP Filter to search for objects I’m after I’m tempted to use line break here and there to make whole thing easier on eyes of future reviewer (even if the only person to read the code is me “few weeks later”).

Continue reading

Quick tip: regex groups and ‘-split’

If you use –split as often as I do you probably had occasional issue with understanding why certain splits work as expected, and some produce results different from what you anticipated. Recently one of MVPs, Oisin Grehan, shed some light on the reason why this is the case. I thought it might be worth sharing in case you’ve had this issue and you are pulling your hair trying to figure out what’s going on.

Continue reading

Managing Linux via OMI: Packaging


This is sixth and final part of the series. You can find outline of the whole series here. We already have OMI server up, running and accessible from outside and we have test Lin_Process implemented on it, with several properties and single method: Kill. Today we will build our own CDXML-based module that will surround remote CIM calls in cmdlet-like functions. This package won’t be auto-generated, I had no luck finding procedure to do that (truth be told: I haven’t tried hard and wanted to learn CDXML concepts anyway). We move back to PowerShell than…

Continue reading

Managing Linux via OMI: Implementation (2)


This is fifth part of the series. You can find outline of the whole series here. We already have OMI server up, running and accessible from outside and we have Lin_Process class implemented, with two properties: PID and cmdline. Today we will extend our schema to few other properties and we will add a method to it. Unfortunately, it means more amateur C++ code, but also more fun and information retrieved remotely from our test, CentOS box.

Continue reading

Managing Linux via OMI: Implementation (1)


This is fourth part of the series. You can find outline of the whole series here. We already have OMI server up, running and accessible from outside and we have test class implemented on it. Time to create something useful. We start with processes because they are objects very convenient for demo purposes. Normally we would create class that is based on existing one, e.g. CIM_UnixProcess. But before we do it right, we will try to create something that at least works and does what we need. Why? Well, if you look at CIM_UnixProcess schema you will find plenty of keys there, not to mention other properties that would require values at certain point. We will come back to this later, when we know what those values should be.

Continue reading

Managing Linux via OMI: Configuration

PowerShell-Control-Linux-ConfigureThis is third part of the series. You can find outline of the whole series here. We already have OMI server up and running, but so far it’s not accessible from outside. Our plan is to perform operations inside PowerShell, so remote access is necessary. Next, we will create static, example provider and try to access data from it remotely. Once we understand some basic concepts and code structure – we will be able to start implementing something for real.

Continue reading

Managing Linux via OMI: Installation

PowerShell-Control-Linux-InstallThis is second part of the series, first one that actually explains anything. You can find outline of the whole series here. Before we start to play with Open Management Infrastructure (OMI) on Linux box we need to have two things: Linux box (obviously) and OMI installed on it (tell me something I don’t know!) First part is easy these days, so I will mention it briefly. Next part is also very natural to anybody who installed anything on Linux (outside of “normal” packaging mechanism, that – to me knowledge – is not supported for OMI yet). Finally we will change our system to run OMI server every time we boot. My way is probably far from best practices for Linux, so feel free to jump in and correct me there. Puszczam oczko 

Continue reading

Managing Linux via OMI: Roadmap

PowerShell-Control-Linux-RoadMapThis is 1st part of series of blog posts related to my recent work with Linux and Open Management Infrastructure (OMI). I will have pretty long talk on DAL concept next week and while preparing for it I decided that I need something to demo OMI on. In the perfect world I would take shining new Cisco Nexus (one of models that have OMI as an option) or one of Arista gears (with same prerequisite) and demo it there. There were two pain points in this approach: I have no modern switches lying around at my home/ work was major one. Minor one? It would be pretty hard to take it with me to the presentation. If you compare physical device and virtual machine running on a laptop it’s kind of no-brainer witch one you should pick, right? Puszczam oczko

Continue reading