header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left
Jun 17

Written by: Karl Prosser
6/17/2008 9:12 PM

Given the context on the last few posts. I've made a simple helper method in C# that can take a simple powershell hashtable and create a PSCustomObject based on it. Here is an example of how you can call it.

[snapinini.newobjecthelper]::newObjectFast(@{name="karl";age=31;now = [datetime]::Now})

very simple and its at least 6 times faster than the closest other technique in powershell. Most of hte overhead is in creating the hashtable. (otherwise its 90 times faster). The hashtable syntax is very convenient however maybe even its overhead is too much and we deserve a better way.

Here is the C# method. Its pretty basic stuff.

 

public static PSObject newObjectFast( Hashtable noteproperties )
{
PSObject obj = new PSObject();
if (noteproperties != null)
foreach(DictionaryEntry item in noteproperties)
obj.Properties.Add(new PSNoteProperty((string)item.Key,item.Value));
return obj;
}

- Karl

Tags:

Your name:
Title:
Comment:
Add Comment    Cancel  
 

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Blogs
  
Search Blogs
  
Archives
  
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer