header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left
Random Cmdlets
Set-ManagedFolder
Use the Set-ManagedFolder cmdlet to modify the settings of managed folders.


Remove-UMVirtualDirectory
The Remove-UMVirtualDirectory cmdlet removes an existing virtual directory from a computer that is running Microsoft Exchange Server 2007 that has the Client Access server role installed.


Clear-ItemProperty
Deletes the value of a property but it does not delete the property.


Import-Bitmap
Loads bitmap files.


New-ActiveSyncMailboxPolicy
The New-ActiveSyncMailboxPolicy cmdlet is used to create a new Microsoft Exchange ActiveSync mailbox policy object.


Join-Path
Combines a path and child-path into a single path. The provider supplies the path delimiters.


Disable-TransportRule
Use the Disable-TransportRule cmdlet to instruct the Transport Rules agent to disable the processing of a specific transport rule for all e-mail messages that pass through a computer that has the Microsoft Exchange Server 2007 Hub Transport server role or the Edge Transport server role installed.


ConvertFrom-SecureString
Converts a secure string into an encrypted standard string.


New-MailContact
You can use the New-MailContact command to create a new mail-enabled contact.


Disable-UMServer
The Disable-UMServer cmdlet sets the status of a Unified Messaging (UM) server to disabled. This prevents the Unified Messaging server from processing UM calls.


  
Latest Scripts from PoshCode.org

Exch07 Quota Report
Power Shell 1 script used to grab mailbox stats for a Exchange 2007 server. It saves the information into a .csv file by changing the $OUTFILE variable. The script is pretty basic but it's a simple way of having a history of how people use their inbox space. There is no method for managing the saved files. I just make it a point to delete them when I run my months end maintenance.

Out-DataTable
Creates a DataTable for an object, based on script by Marc van Orsouw

Modified WOL impl.
This function can send WOL packages. Note that this a modified version of code already floating online. You need to specify the Mac address as a string. Optionally use -Ports (0,1000) to specify the udp ports. (use -verbose to show which pacakges are being send).

Invoke-SqlCmd2
Modeled after SQL Server 2008 Invoke-Sqlcmd, but fixes bug in QueryTimeout.

EchoTest.cmd
A DOS cmd script to show how your arguments look to "native" console apps

Set account password
This script will allow you to set the password for an account on a local or remote machine/s. A report is then generated when done along with an error log. Scripts accepts pipeling input for the computer/s. If any errors are encountered, a log will be generated as well.

Enable/Disable FusionLog
http://georgemauer.net/blog/enabledisable-fusionlog-powershell-script/ Enabling/disabling your Fusion Log every time you need to figure out why assembly binding has gone wrong is a hassle. So here you go.

Start-Presentation
My current (WPF 4 compatible) PowerBoots-based Presentation Module. *REQUIRES* "PresentationFrame.xaml":http://poshcode.org/get/2104 and, of course, "PowerBoots":http://boots.codeplex.com This isn't really ready to be shared, but I always tell people if you wait until after you have time to clean it up, you'll never share it -- so since I'm unlikely to actually finish cleaning this up any time soon -- here it is. "See the screenshots for an example":http://HuddledMasses.org/images/PowerBoots/PowerBoots%2dPresentation.png

PresentationFrame.xaml
A required file for my "PowerShell Presentation module":http://poshcode.org/2105

Get-RemoteRegistry
A script to do a query on a remote registry key or value. Because the Registry provider inexplicably doesn't support it.
  
 

April 5th, 2010,

The 2010 Scripting Games are coming...

2010 Scripting Games

 Fire up your scripting editor and get ready to write some PowerShell!

Check out the Study Guide and register for the games!

-Steven Murawski
Co-Community Director

Community News
iPowerShell V2 Now Available

Sapien just released iPowerShell V2, which is now available in the Apple app store.  What is iPowerShell?

From Ferdinand Rios -

PowerShell In Practice

From Marco Shaw -

Check out http://www.manning.com/siddaway

Get the ebook or printed edition (not available yet), and use the discount code "marcoshell40" when checking out and get 40% off the regular...

Thomas Lee Joins PoshComm Directors

PowerShellCommunity.Org is happy to announce that Thomas Lee, Powershell MVP and noted trainer, is joining our ranks as a Community Director. 

Thomas is also responsible for a good many of the PowerShell...

Looking to get started with Modules?

Check out the PowerShellPack from James Brundage, which contains modules for making GUI's, add-ons for the ISE(Integrated Script Editor), system tools, and...

PowerShell Virtual Launch Party

PowerShell V2 Virtual Launch Party!

Jeffrey Snover, Hal Rottenberg and Jonathan Walz (hosts of the PowerScripting Podcast) hosted a PowerShell V2 Virtual Launch Party on Thursday, Oct 22nd, 9:30 PM EDT (GMT-4). 

More details...

  
Recent Blog Entries
Jun 17

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

Based on the performance testing and work being done by myself , mow , Brandon Shell and others the question has come up what is the quickest way to generate a PSCustomObject, whether in script , on in C#, and how do you even do it in C#?

Some typical ways of doing in PowerShell have been either something like the following trick:

or with using the Add-member cmdlet as below:

$a = 1 | select a , b , c , d
$a | add-member -membertype noteproperty -name status -value done

however both are really slow. There is another way to do it in script, and that is directly with the PSobject, but still PowerShell (especially version 1) has a huge overhead when creating new objects with new-object but below is an example none the less.

$obj = new-Object system.Management.Automation.PSObject
$note = new-object System.Management.Automation.PSnoteproperty "karl" , "a value"
$obj.psobject.members.add( $note );

But if you really want to do speed, or if you have need to generate these objects in a cmdlet regardless of speed here is how you can do it in C#.

public static PSObject newPsCustomObject2()
{
//Creating a PSobject without any parameters in the constructor creates a PSCustomObjectg
PSObject obj = new PSObject();
//PSNoteProperties are not strongly typed but do contain an explicit type.
obj.Properties.Add(new PSNoteProperty("age",24));
obj.Properties.Add(new PSNoteProperty("name","jon"));
//Alias allow you to cast one property as another as well as just plain aliasing
obj.Properties.Add(new PSAliasProperty("ageasstring","age",typeof(string)));
return obj;
}

 

Some notes about the above, I didn't show how you could add ScriptProperties or ScriptMethods yet as I wanted to keep it simple and not cover creating scriptblocks. Before I go lets performance test this baby compared to creating this in pure PowerShell.

So in the:

1) first corner we have creating the object with select-object, then setting the properties.(but we can't set the alias)
2) Creating the object with new-object, then using add-member to add all the properties.
3) calling our static method above.

#select-object version
for($i = 0;$i -lt 50000;$i++) { $a = 1 |Select-Object age, name; $a.age = 24; $a.name = "john" }
#add-member version
for($i = 0;$i -lt 50000;$i++)
{ $a = new-Object psobject;
$a | add-member -membertype noteproperty -name age -value 24
$a | add-member -membertype noteproperty -name name -value "john"
$a | add-member -membertype aliasproperty -name "ageasstring" -value "age" -secondvalue "string"
}
#Our fast version
for($i = 0;$i -lt 50000;$i++) { $a = [snapinini.newobjecthelper]::newPsCustomObject2(); }

so we are creating 50,000 objects and the results are.

select-object 27.15 seconds.
add-member 118.79 seconds
C# method 1.9 seconds.

and i used to complain with the performance hit of a address lookup for a method in a C++ virtual method table!!

at worst the official add-member technique is over 60 times slower than calling C#, and thats not really RAW C#, thats still powershell invoking a C# method 50,000 times, and powershell managing a loop.

if fact just to test i added another test

$a = [snapinini.newobjecthelper]::newPsCustomObject3();

where newPSCustomObject3() moves the 50,000 loop to inside C#.. and here the speed is 0.95 seconds, so about half the speed of invoking the C# method from powershell each time - this speed difference I am happy with though. The PowerShell team seem to have done a good job of invoking C# methods quickly.

Another day I should investigate the speed of creating objects that have been created with the extended type system.

I'd love if somebody can run these tests in v2.

Also sometime soon I shall share a helper function you can use to quickly generate a PScustomObject with properties and values you specify in script.

-Karl

Tags:

1 comments so far...

Re: generating a "PropertyBag" aka PScustomObject in C#

The route to a happier life is through happy thoughts. Not just because they make you feel better immediately... but because happier thoughts give you a stronger and more stable foundation to your life. You are in control rather than being bounced around by life.
mcpd

By alandoland on   5/28/2010 10:47 PM

Your name:
Title:
Comment:
Add Comment    Cancel  
  

We have a new sponsor!  Introducting Pragma Systems.  See the home page for details.

right
   
footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 footer
footer