header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left
Random Cmdlets
New-QADGroup
Create a new group in Active Directory. Supported are both Active Directory Doman Services (AD DS) and Active Directory Lightweight Directory Services (AD LDS).


Set-Contact
Use the Set-Contact cmdlet to modify the settings of an existing contact.


Get-TabExpansion
Gets matching tab expansions.


Suspend-Message
Use the Suspend-Message cmdlet to prevent delivery of a particular message in a queue on a computer that has the Hub Transport server role or the Edge Transport server role installed.


Move-Item
Moves an item from one location to another.


Remove-ActiveSyncMailboxPolicy
The Remove-ActiveSyncMailboxPolicy cmdlet enables you to remove a specific Exchange ActiveSync mailbox policy from a Microsoft Exchange Server 2007 computer that has the Client Access server role installed.


Get-WebDAV
The Get-WebDAV cmdlet implements an easy-to-use interface to the Web Distributed Authoring and Versioning protocol (WebDAV).


Ping-Host
Sends ICMP echo requests to network hosts.


Test-UMConnectivity
The Test-UMConnectivity cmdlet can be used to test the operation of a computer that has the Unified Messaging server role installed.


Get-TransportConfig
Use the Get-TransportConfig cmdlet to view organization-wide e-mail transport configuration settings on computers that have the Hub Transport server role or the Edge Transport server role installed.


  
Latest Scripts from PoshCode.org

egg_timer
A script I submitted for Event 10 of the Scripting games. Displays a simple Windows Form that counts down three minutes. It makes a good example for using Windows forms.

SnapReminder
Remind the users of their snapshots - for use in VMware, see this post for more details: http://www.virtu-al.net/2009/06/22/powercli-snapreminder/

LibrarySqlBackup
Standalone script adapted from SQL Server Powershell Extensions (sqlpsx) http://sqlpsx.codeplex.com. Defines SQL Server backup and restore functions.

Format-TablePlus
This is a wrapper function for Format-Table that adds a @-Width@ parameter, and a @-PadEnd@ parameter (without which it trims the end of every line of output. Set -PadEnd to get the original Format-Table behavior of adding needless whitespace on the end of every line of output.

Colorize Subversion SVN
Colorize STAT, UPDATE and DIFF (without params) commands output for Subversion (svn) and Mercurial (hg). Here's a PowerShell functions that you can use to make those numerous commands you run every day via the PowerShell CLI a little easier to read by adding colors. Autodetect for svn or hg. Update autodetect to work with psdrives that are a UNC path. Also now works with repositorys in the root directory of drive. Added $args to each function so you can do things like sd -r2 -rtip -U0

Get-DirSize
A v2.0 function to recursively get the sizes of all subdirectories under a root path.

vProfiles
vProfiles V1.1 By Alan Renouf http://virtu-al.net, copies vSwitches and PortGroups from one host to another.

Prevent-Screensaver
Simulate user activity to prevent desktop lock or screensaver for specified period of time

TabExpansion for V2CTP3
The most needless, useless and worthless Tabexpansion for powershell.exe(v2.0CTP3) in PoshCode. Update: # Parameter name (and command alias) expansion with Ctrl+E ls -f *.txt -r | ? { $_.LastWriteTime -lt "2009/5" } | Select-String powershell -e OEM<Ctrl+E><tab>. <br> Get-ChildItem -Filter *.txt -Recurse | Where-Object { $_.LastWriteTime -lt "2009/5" } | Select-String powershell -Exclude OEM<tab> Get-ChildItem -Filter *.txt -Recurse | Where-Object { $_.LastWriteTime -lt "2009/5" } | Select-String powershell -Encoding OEM<tab> Get-ChildItem -Filter *.txt -Recurse | Where-Object { $_.LastWriteTime -lt "2009/5" } | Select-String powershell -ErrorAction OEM<tab><tab>...

TabExpansion
The most needless, useless and worthless Tabexpansion for powershell.exe(v1.0) in PoshCode. Please dot souce this script file to use. Update:. # WMI Namespaces expansion for Get-WmiObject gwmi -Namespace <tab>. Get-WmiObject -Namespace root\asp<tab>. # WMI Classes expansion which is corresponding to WMI Namespace (*) gwmi -Namespace ROOT\CIMV2\ms_409 -Class <tab>_<tab>. (*) it needs to remove old $PSHOME\WMIClasses.txt if it exists.
  
 

April 24th, 2009.

Idera, one of our sponsors has joined forces with Don Jones to create some super PowerShell videos that you can find HERE.  Best of all...  They are FREE!

Follow the link above for more information.  Don Jones covers the basics of PowerShell, using PowerShell and Active Directory, using PowerShell and Exchange 2007, using PowerShell and SQL Server 2008, and using PowerShell to manage servers and clients.

The Community has just taken a great leap in getting the word out about how cool PowerShell is!

Marco Shaw - Co-Community Director

Community News
New sponsor: Compellent

PowerShellCommunity.org has an exciting new sponsor: Compellent.  Just added to our sponsors page:

Compellent is a leading provider of enterprise-class network storage solutions...

Microsoft TechDays Defy All Challenges

On April 1st, 2009, Microsoft is putting on a free 24 hour virtual event covering developer-related topics.

There will be 95 live sessions provided via Live Meeting in the following tracks:
*Windows Development and Frameworks
*Windows Mobile Development
*Office...

Microsoft releases IIS7 PowerShell snapin

The full details are HERE.  Microsoft has just released a production version of a IIS snapin for managing IIS7 on Windows Server 2008.  This snapin is independent of any features shipping with Windows Server 2008 R2 (like PowerShell...

New Sharepoint and SQL forums

Due to recent interest in the forum, we've added two new discussion areas:

PowerShell Expert Panel at TechEd EMEA 2008

 We are extremely proud of the the job that Jonathan Medd (of the Get-Scripting Podcast) did at TechEd EMEA 2008 with a panel discussion which was made possible by support from PowerShellCommunity.org. You can find the video on

  
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:

Your name:
Title:
Comment:
Add Comment    Cancel  
  

PowerShellCommunity is sponsoring this year's Microsoft Technet Scripting Games, along with the new PoshCode.org. Submit your entry today!

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