Service Endpoints in config Files suchen
Kürzlich stand ich vor der Aufgabe, alle Websites zu finden, die einen bestimmten Webservice nutzen. Ziemlich schnell kam ich auf den Gedanken, die web.config aller Websites nach dem Endpunkt bzw. der IP des Servers zu durchsuchen, auf dem der Service läuft. Nach einigem überlegen konnte ich das ganze in einem Einzeiler mit der Powershell lösen:
Get-ChildItem –Recurse –Filter *.config | foreach-object { $_ | Select-String “(192.168.1.250)|(someService.svc)”}
Das ganze ausgeführt interaktiv von der Powershell über das Verzeichnis, in dem die Websites liegen. Das ganze könnte man nun in verschiedene Richtungen erweitern. Man könnte beispielsweise das ganze in ein Script packen, in dem man als mögliche Parameter den Filter, den Suchstring (der übrigens ein Regex ist) oder den Pfad in dem gesucht werden soll übergeben wird. Des Weiteren könnte man das Ergebnis in eine Datei oder in ein GridView ausgeben. Das schöne hier sind die vielen Möglichkeiten, die die Powershell hier bietet. Bei Bedarf kann man die Treffer auch noch in weiteren Befehlen nutzen und so z.B. den Service durch einen anderen ersetzen.
Bringing some color into Posh
During the last days of 2011 I wrote a little Powershell module for mercurial, inspired by the posh-hg module by Keith Dahlby. It is just a small part of my Powershell infrastructure, but one of the most useful.
The main benefit is highlighting the Mercurial repositories on my local machine in different colors, depending on their status. White means, it is just a normal directory. Green stands for a Repository with nothing to do, so red is pretty obvious: Get to work! This is the point, where posh-hg comes into play. When I step into the winPackage Folder, posh-hg gives me more information about what to do. Whenever I browse my project folders I can see at first sight, if one of my co-workers has added something to a repository.
Technically it is just a call to hg-status, and then coloring the output. I override the dir alias, and format the output of get-childitem. I’ve seperated the code into two little functions, so you can easily alter it for git/svn or whatever VCS you wanna use within the comannd.
You’ll find the code in a gist.
