Sunday, December 30, 2018

Powershell Automation from C#.NET

You could call Powershell Scripts from .NET (C#) application with ease using System.Management.Automation. A sample has been provided here, which utilizes RunSpace pool for more configurablity. i.e You could manage the thread pool, for running the Powershell scripts from C#. i.e You could run it on the calling thread, or on a pool of different threads for higher level of parallelism.


You could find a highly configurable SignalR ChatRoom application here, which make use of Powershell automation to achieve dynamic functionality as needed.


chatroom2

Friday, December 28, 2018

Powershell: High Performance Registry Search

Find a high performance registry search implementation through powershell here. Sample searches can be found here. You could search based on;

a. Registry Path Names

b. Registry Value Names

c. Registry Values

Like match would be the default. You could specifiy (-searchExact) for exact matches. The implementation provides a wrapper over the native ‘REG QUERY’ command line tool. Native registry search through Powershell lacks performance, pretty slow and runs for hours in certains cases.


Sample: (Search-Registry -tokenToSearch "aero.theme" -tokenType Value -pathsToSearch @("HKLM"))

Searches registry values having the string token “aero.theme”


registry

Sunday, December 16, 2018

Generic Log Parser (Filter By Log Dates–TimeZone, Log Expression) in Powershell

Find a Generic Log/Text Parser written in PowerShell here. This Parser allows filtering any kind of Logs (Windows Built in IIS, CBS or others) including Custom Logs from your application server environments. This parser also take the Time-Zone information into account, in which the Log Entries being written. The following are the key parameters by which Logs are being extracted;

a. Filter Start Log Date Time

b. Filter End Log Date Time

c. Time Zone in Which Filter Log (Above) have been given

d. Server Log Folders (network shares) from which logs will be parsed

e. An expression, which will be matched against log entries and only matching ones will be picked.

f. A print Time Zone, in which the dates of the selected Log Entries will be written to the output file

g. A Log Control File, which contains the structure of the Log File Formats.

e.g. Sample one given here, which defines the structure for the built in CBS and IIS Logs.

You could also define your own Log file formats from your environments and could include to this Control files. “LogEntryFormat” property of the Log Control entry, should contain three tokens namely DATE, TIME and ENTRY with the exact casing. These defines the positions in the Log entry to pick the Date, Time and the rest of the Log Entry to be parsed.

(Eg of Windows CBS Log: "LogEntryFormat": "(?<DATE>\\d{4,4}-\\d{1,2}-\\d{1,2}) (?<TIME>\\d+:\\d+:\\d+), (?<ENTRY>.*)")

A sample parsing can be found here.

To define a new Log Control entry for a custom log in your application environment, insert a similar entry to the Log Control Files and give it a unique name. The same should be specified for “logTypeControlKey” parameter. (e.g. ‘’logTypeControlKey = "CBS_LOG"”)