Call us toll free: +41 800 789 50 12
Top notch Multipurpose WordPress Theme!

Dynamic and interactive filtering in Powershell

by ivolooser Comments: 0

Filtering in Powershell are one of the most expressions i’m use for drill down get-cmdlet results. There are so much situations we would like to have some simple and clear technique to see the results in different views.  

As an Example I will use get-process with three views:  

  1. SlowMotion (More about here.) 
  2. Startet Services 
  3. Stopped Services who begins with “VW*”

The most scripts are using one view per File.

Get-ServicesByStopped.ps1 Get-ServicesInSlowMotion.ps1

The scripts above are displaying two different views. This will give you very fast a big collection of files. 

One other approach is display views over Parameters. Maybe you will use

.\Get-MyProcesses.ps1 –ReportByVMWareStopped

Example 1:

	[switch] $ReportBySlowMotion, 
	[switch] $ReportByStartet,
	[switch] $ReportByVMWareStopped
	foreach($process in @(Get-service))
	{$process; Start-Sleep -milliseconds 500}
{Get-service | ?{$_.Status -eq "Startet"}}
{Get-service | ?{$_.Status -eq "Stopped" -and $_.Name -ilike "VM*"}}

Using filters dynamic is getting scripting simple to extend , and flexible to use.  

Basicly I create a few lines that do the following:  

  • First normaly create filters in the Syntax “filter Filter-xxx{…}”. This is the best Advantage because just define the filter und you will get the selection for the filter in your Script.
  • Load the filters when its needed from the Function Provider
  • Display the avaible filters so that the user can choose the right one.
  • Load the definition and show the result as selected.

Example: Dynamic Filters

## Creating the Filters
filter Filter-VMWare-Stopped{if($_.Status -eq "Stopped" -and $_.Name -ilike "VM*"){$_}}
filter Filter-Startet{if($_.Status -eq "Startet"){$_}}
filter Filter-SlowMotion{$_; Start-Sleep -milliseconds 500}
## Get All Filters by Name (Scoped filters need some Cleanups)
$filterobjects = & get-childitem function: | ?{$_.CommandType -eq 'Filter'}
$filterobjects | ft name
$choosedFilter = read-host "`nChoose your Filter"
## Choose the filter Definition (For the Filter-Stopped it will contain if($_.Status -eq "Stopped"){$_})
$choosedFilterDefinition = (get-item function:$choosedFilter).Definition
## The Where-Object need's a Scriptblock.
$currentFilter = [scriptblock]::Create($choosedFilterDefinition)
get-service | where-object $currentFilter | ft -autosize Name, Status, DisplayName


Find MSSQL Server Errorlog Location with Logparser

by ivolooser Comments: 0

We are running much SQL Servers with different located ErrorLogs. Sometimes its usefull to find quick the Location from the Logs. I did a Command that gives me the Errorlog location to the Commandpromt, so i can copy them on my Client and open it in my lovely Editplus for furter troubleshooting.

Find the Location of the SQL Server Errorlog SQL Server 2005

logparser “select strcat(strcat(‘\\\\’,strcat(computername, ‘\\’)),REPLACE_CHR(REPLACE_STR(value, ‘-e’, ”), ‘:’, ‘$’)) from ‘\\MYServer\HKLM\SOFTWARE\Microsoft\Microsoft SQL Server’ where value like ‘%errorlog%’” -i:REG -recurse:10

Find the Location of the SQL Server Errorlog SQL Server 2000

logparser “select strcat(strcat(‘\\\\’,strcat(computername, ‘\\’)),REPLACE_CHR(REPLACE_STR(value, ‘-e’, ”), ‘:’, ‘$’)) from ‘\\MYServer\HKLM\SOFTWARE\Microsoft\MSSQLServer’ where value like ‘%errorlog%’” -i:REG -recurse:10

Build a free IPhone/ IPod Holder

by ivolooser Comments: 0

Here i will show you how you can Build a quick nice free IPod / IPhone holder with a CD-Case.

  1. You need an old CD-Case and the Original IPhone/IPod Case
  2. Cut  with a Knife a littel pice on bothe side from the top pice.
  3. After that your CD-Case should hold on a Table like this.
  4. Now sticking you Original IPhone/IPod Case to the CD-Case
  5. Take some time to Decorate it.
  6. Mabe you whould use it as a Nightclock

Keep your Sharepoint Mail Enabled list Email Adress clean

by ivolooser Comments: 0

Did you once give the possibility in Sharepoint for Enabled Lists or Libraries and thought, oops the Sharepoint Users can make a real big mess with the Email Adresses in our Active Directoy? 

Maybe you give External partners access to Lists via Email. How does the external Customers think about your Company if an Sharepoint user gives mail like it come up in his Mind. For Example one uses and an other take

We implemented a small script whitch gives the Sharepointusers a little clue, what name he can use to give good email adresses any Enabled List.

We made Adaptions in Files EmailSettings.aspx from %HIVE12%. Keep in mind that the files could be  damage after an Farmupdate.

In the File EmailSettings.aspx go above the begin Javascript part and drop the Following Serverside Script in:

    SPWeb oWeb = SPControl.GetContextWeb(Context);
    Guid requestListGuid = new System.Guid(Request.QueryString["List"]);
    SPList selectedList = null;
    string listName = "nodefined";
    foreach (SPList list in oWeb.Lists)
        if(list.ID == requestListGuid)
            listName = list.Title;
    string webTitle = oWeb.Name;
    webTitle = System.Text.RegularExpressions.Regex.Replace(webTitle, @"[^0-9a-zA-Z.]", ".");
    // How the Email Generation Rules work.
    // 1. SiteTitle-ListTitle
    // 2. Only Characters 0-9a-zA-Z._- are allowed
    // 3. Alle duplicated points are replaced with singlepoints
    String tmpEmailAlias = webTitle;
    tmpEmailAlias = tmpEmailAlias + "-" + listName;
    tmpEmailAlias = System.Text.RegularExpressions.Regex.Replace(tmpEmailAlias, "[.]+", ".");
    tmpEmailAlias = tmpEmailAlias.Replace("À", "A");
    tmpEmailAlias = tmpEmailAlias.Replace("Á", "A");
    tmpEmailAlias = tmpEmailAlias.Replace("Â", "A");
    tmpEmailAlias = tmpEmailAlias.Replace("Ã", "A");
    tmpEmailAlias = tmpEmailAlias.Replace("Ä", "A");
    tmpEmailAlias = tmpEmailAlias.Replace("â", "a");
    tmpEmailAlias = tmpEmailAlias.Replace("ã", "a");
    tmpEmailAlias = tmpEmailAlias.Replace("ä", "ae");
    tmpEmailAlias = tmpEmailAlias.Replace("à", "a");
    tmpEmailAlias = tmpEmailAlias.Replace("á", "a");
    tmpEmailAlias = tmpEmailAlias.Replace("È", "E'");
    tmpEmailAlias = tmpEmailAlias.Replace("É", "E'");
    tmpEmailAlias = tmpEmailAlias.Replace("Ê", "E");
    tmpEmailAlias = tmpEmailAlias.Replace("Ë", "EA");
    tmpEmailAlias = tmpEmailAlias.Replace("ê", "e");
    tmpEmailAlias = tmpEmailAlias.Replace("ë", "ea");
    tmpEmailAlias = tmpEmailAlias.Replace("è", "e");
    tmpEmailAlias = tmpEmailAlias.Replace("é", "e");
    tmpEmailAlias = tmpEmailAlias.Replace("Ì", "I");
    tmpEmailAlias = tmpEmailAlias.Replace("Í", "I");
    tmpEmailAlias = tmpEmailAlias.Replace("Î", "I");
    tmpEmailAlias = tmpEmailAlias.Replace("Ï", "I");
    tmpEmailAlias = tmpEmailAlias.Replace("î", "i");
    tmpEmailAlias = tmpEmailAlias.Replace("ï", "i");
    tmpEmailAlias = tmpEmailAlias.Replace("ì", "i");
    tmpEmailAlias = tmpEmailAlias.Replace("í", "i");
    tmpEmailAlias = tmpEmailAlias.Replace("Ò", "O");
    tmpEmailAlias = tmpEmailAlias.Replace("Ó", "O");
    tmpEmailAlias = tmpEmailAlias.Replace("Ô", "O");
    tmpEmailAlias = tmpEmailAlias.Replace("Õ", "O");
    tmpEmailAlias = tmpEmailAlias.Replace("Ö", "OU");
    tmpEmailAlias = tmpEmailAlias.Replace("ô", "o");
    tmpEmailAlias = tmpEmailAlias.Replace("õ", "o");
    tmpEmailAlias = tmpEmailAlias.Replace("ö", "ou");
    tmpEmailAlias = tmpEmailAlias.Replace("ò", "o");
    tmpEmailAlias = tmpEmailAlias.Replace("ó", "o");
    tmpEmailAlias = tmpEmailAlias.Replace("Ù", "U");
    tmpEmailAlias = tmpEmailAlias.Replace("Ú", "U");
    tmpEmailAlias = tmpEmailAlias.Replace("Û", "U");
    tmpEmailAlias = tmpEmailAlias.Replace("Ü", "U");
    tmpEmailAlias = tmpEmailAlias.Replace("û", "u");
    tmpEmailAlias = tmpEmailAlias.Replace("ü", "u");
    tmpEmailAlias = tmpEmailAlias.Replace("ù", "u'");
    tmpEmailAlias = tmpEmailAlias.Replace("ú", "u'");
    tmpEmailAlias = tmpEmailAlias.Replace("Ý", "Y");
    tmpEmailAlias = tmpEmailAlias.Replace("ý", "y");
    tmpEmailAlias = tmpEmailAlias.Replace("ñ", "n");
    tmpEmailAlias = System.Text.RegularExpressions.Regex.Replace(tmpEmailAlias, "[ ]", ".");
    tmpEmailAlias = System.Text.RegularExpressions.Regex.Replace(tmpEmailAlias, @"[^0-9a-zA-Z._-]", string.Empty);
    tmpEmailAlias = tmpEmailAlias.ToLower();
    string emailAlias = tmpEmailAlias;

Here we do the biggest part of the Script. Find the Liste Title and the Webname and clean it up with some Replacements. As the First Line inside the Javascript Section place the following single Line. That Line make sure that we get the cleaned EmailAlias as an Javascript Value.

var l_EmailAlias = '<%=emailAlias%>';

And for the Last in EmailSettings.aspx replace the Following Part:

function SetControlsDisabled(state)
    document.getElementById("<%= TxtAlias.ClientID %>").disabled = state;

with the little next part:

function SetControlsDisabled(state)
        document.getElementById("<%= TxtAlias.ClientID %>").disabled = state;
        document.getElementById("<%= TxtAlias.ClientID %>").value = l_EmailAlias;
        document.getElementById("<%= TxtAlias.ClientID %>").disabled = state;
        document.getElementById("<%= TxtAlias.ClientID %>").value = "";

Thats it and have fun.

Crud for Turbogears with MyGeneration

by ivolooser Comments: 0


Some years ago i was doing Webdevelopment with ASP Classic from Microsoft. For creating my Crud’s i was choosing MyGeneration at this time. I got experience with MyGeneration and was very happy how fast i got up Editable Tables.

But for now, im playing with Turbogears at it makes alot of fun. Some Months ago i tried tgcrud and some weeks ago dbsprockets. Both developers did a very good job, sure, but for me both had some limitation.

  • tgcrud does not support insert Identity automatic from the Database Table. I now i’m a poor guy. Why i’m not just use the commandline Option? The second one was no selection for which fields are Diplayed in the grid and in the Edit mode. Much manual work and i had no idea how i can extend for my own use.
  • dbsprockets i had to adapt the design first, just copy past,  to made the admin forms in my look. Ok, i got my personalized view for admin but nothing more. Extend the edit forms was to hard for me.

So i decided to make public my personal MyGeneration Template.

How it works

Right click the Template Turbogears Crud in MyGeneration, select your Fields for Columns in Grid and Columns for Editing and click OK.


After drop the generated Folder UserController in your Project subfolder controllers and link to them in You find more  Information in the section Step by Step.

What you get?

  • Automatic creation of Basic Controllers for Create, Update and Delete.
  • Name the controller different to the Tablename
  • Name the Fields in the Listview different to the Names in the Database.


MyGeneration is a .Net Software. You should use a Windows Machine to Generate the Templates.

Have you a Mac? I’m generate my Contollers from a Virtual Windows XP Machine against a MySQL Database which is running on my Leopard. The same Template on my Laptop with Windows only against XAMP MySQL works also.

I never investigated it works with SqlLite. For my point of view it only works with MySql.

More Limitations:

  • No Support for PrimaryKeys over more then one Column
  • Foreignkey handling needs to be done by hand.
  • For Blob Column is no File field generated
  • No Paginate Grid (Currently)

Step by Step

Setup MyGeneration
  1. Grab MyGeneration
  2. Place the File Turbogears.Crud.vbgen to C:\Programme\MyGeneration13\Templates\Turbogears\Turbogears.Crud.vbgen
  3. Create Connection to MySql with Driver MySql2 Sample Connection: Database=project1;Data Source=localhost;User Id=root;Password=1234;
Prepare a Turbogears Project
  1. Open your Terminal
  2. easy_install turbogears
  3. easy_install sqlalchemy
  4. easy_install tw.forms
  5. create your Project with Identity tg-admin quickstart –sqlalchemy -t tggenshi
  6. as a sample give the name project1
  7. Point Connection to Database with sqlalchemy in dev.cfg
  8. Create Tables in Database tg-admin sql create
  9. go to your app.cfg and set toscawidgets.on = True
Create Controllers
  1. Open MyGeneration (Start -> Programs -> MyGeneration 1.3 -> MyGeneration)
  2. Select your Template in MyMeta Browser and give the class Name from SQLAlchemy as Alias in UserMetaData and Save User Meta Data image
  3. Right click Template Turbogears Crud and choose Execute
  4. Define Settings image
  5. go to your Output file path and take a look if the name of your Controller is UserController image Maybe your Ouput file path is different from mine.
  6. copy the Folder UserController to .\project1\project1\
  7. expose UserController in the File with from UserController import UserController users = UserController()
  8. See what you get image image image
  • If you want change the Column names for the List and the Labels for edit you can set the Column Alias in MyGeneration.
  • Are the Templates not exactly for your needs, just change it.


SHA1 Hash from a String

by ivolooser Comments: 0

There is not that much to say. Attached is a Script that generates a SHA1 Hash from a String.

Why for me? We have several Servers they are storing files in a specified format on different folders. I should write a Powershell Script who grab the content of each file and save the replace string back.

For testing purpose i store the File first in two local folder. One is called ArchivOriginal and ArchivEdited. For the each filename i whould like to give them a traceable name like server_share_folder1_folder2.txt. But the folder are deep nested somes paths have more then 248  characters. :-(

I create a Reference List with Path:FileName. Here comes my SHA1 script handy form me.

.\Get-SHA1HashFromString.ps1 "//server/share/folder1/folder3.txt"

That its not enougth – because the SHA1 produces char who are not allowed for Windows. Here is my way to cleanup that.

((((((((.\Get-SHA1HashFromString.ps1 "//server/share/folder1/folder3.txt") -replace "/", "slash") -replace "\", "backslash") -replace ":", "doublepoint") -replace "*","star") -replace "\?", "question") -replace "\<", "lt") -replace "\>","gt") -replace "|", "strike" Does you need that then can grab the Script here.

SQLH2 Query

by ivolooser Comments: 0

We’r using SQLH2 from Microsoft to bring sql server related information together on one datastore. Its not a perfect solution when 64-bit is in use, because sqlh2 cannot gather informations from SQL Server x64. In our case its ok to exclude 64-bit servers.

Mostly the Reports are enough declarative to get an overview about a single database growth or changed instance settings. But i’m interessted to find databases where are not backuped since xx days or look at top 10 databases in our environment.

This join is a nice base to get Database information enterprise wide:

mgr_server INNER JOIN mgr_instance
ON mgr_server.srv_id = mgr_instance.srv_id
INNER JOIN c_database
ON mgr_instance.srv_id = c_database.srv_id
AND mgr_instance.inst_id = c_database.inst_id