header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left
Random Cmdlets
Format-Custom
Uses a customized view to format the output.


Enable-UMIPGateway
The Enable-UMIPGateway cmdlet enables a Unified Messaging (UM) IP gateway.


Update-StorageGroupCopy
Use the Update-StorageGroupCopy cmdlet to initiate or resynchronize replication for a specified Microsoft Exchange Server 2007 cluster continuous replication (CCR) or local continuous replication (LCR) database copy.


Remove-UMIPGateway
The Remove-UMIPGateway cmdlet deletes a Unified Messaging (UM) IP gateway.


New-ForeignConnector
Use the New-ForeignConnector cmdlet to create a new Foreign connector on a computer that is running Microsoft Exchange Server 2007 and that has the Hub Transport server role installed. A Foreign connector uses a Drop directory on a Hub Transport server to send messages to a local messaging server that doesn't use the Simple Mail Transfer Protocol (SMTP) as its primary transport mechanism. These messaging servers are known as foreign gateway servers. Examples of foreign gateway servers include Lotus Notes and third-party fax gateway servers. The address spaces that are assigned to a Foreign connector can be SMTP or non-SMTP.


Get-Random
Returns a random number or a byte array.


New-TransportRule
Use the New-TransportRule cmdlet to create a new transport rule that the Transport Rules agent uses when it processes 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.


Move-Mailbox
Use the Move-Mailbox cmdlet to move mailboxes within your organization or between different organizations.


Test-ServiceHealth
Use the Test-ServiceHealth cmdlet to test whether all the required services that are configured to start automatically on a server have started. The Test-ServiceHealth cmdlet returns an error for any service that is required by a configured role and is set to start automatically but is not currently running.


Get-DynamicDistributionGroup
Use the Get-DynamicDistributionGroup cmdlet to retrieve the settings on an existing dynamic distribution group.


  
Latest Scripts from PoshCode.org

Reflection
Helpers for working with .Net classes: Get-Constructor, Get-Assembly, Add-Assembly, Get-Type

WpfBindingHelper
I can't get this to work from PowerShell, but it works fine from C#? * *C#* @PoshWpf.XamlHelper.ConvertToXaml( System.Windows.Markup.XamlReader.Parse( "<StackPanel xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <TextBlock Text='{Binding FullName}' /> </StackPanel>" ));@ * *PowerShell* @[PoshWpf.XamlHelper]::ConvertToXaml( [System.Windows.Markup.XamlReader]::Parse( "<StackPanel xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <TextBlock Text='{Binding FullName}' /> </StackPanel>" ));@ Both of them give back XAML, but in PowerShell ... I'm missing the {Binding FullName} bit.

Out-Posh
A little wrapper script/function to put pipeline output into New-BootsWindow

Replace-InTextFile
A script to do replace strings in text files. Yes, this is just a wrapper around @(gc) -replace | sc@

Export-WLANSettings.ps1
Using netsh.exe to loop through each WLAN on the system and export the settings to the user-provided output-file.

Format-PoshTable
Format-PoshTable puts the output in a WPF DataGrid (inline in PoshConsole, popup otherwise)

Get-FeedInfo
Takes an array of RSS feed URLs and gets the site URL and title..

Email attachments
All descriptions on the web which show how to do this so far have left the email attachment open which means if the script is continuing after the email and you wish to use the file you have attached you will not be able to as it will show as locked, use this example to close the attached file correctly using .Dispose()

Set-WinSchedule
Set-WinSchedule gives a GUI to select a schedule and schedules a task using schtasks. This is a beta. There are still a lot of features to implement. Please read through the synopsis->Description to see the list of features that I hope to get in a final release.

Get-FtpList
A function to get a file listing via FTP and parse it into objects. The default "FtpWebResponse"http://msdn.microsoft.com/en-us/library/system.net.ftpwebresponse.aspx listing comes back in HTML(Hypertext Markup Language) format from my FTP(File Transfer Protocol) server, and this function parses it into objects. However, the string parsing here may not work on the output of your FTP server (if so, please contribute by adding another set of parsing).
  
 

March 4th, 2010,

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

From Ferdinand Rios -

 iPowerShell is an easy to use reference tool for users of Microsoft’s PowerShell scripting language for use on the iPhone or iPod Touch. It contains full descriptions of each and every core PowerShell Version 2 cmdlet, their syntax, parameters and examples of proper usage. It also contains the complete set of “about item” help topics as well as provider and alias help.

Check out the Sapien blog for additional information.

If you have a third party PowerShell module or snapin with help, please contact Sapien (info@sapien.com) so they can integrate those help files with their next release.

-Steven Murawski
Co-Community Director

 

Community News
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...

PowerShell MVPs re-awarded

Congratulations to the PowerShell MVPs that were re-awarded that honor for another year, including our very own Marco Shaw, Hal Rottenberg and Thomas Lee.  Other MVPs that...

  
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  
  

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