header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left
Random Cmdlets
Get-DomainController
Gets a list of available domain controller in the current forest/domain.


Enable-MailPublicFolder
Use the Enable-MailPublicFolder cmdlet to mail-enable public folders.


Clear-Variable
Deletes the value of a variable.


Get-StorageGroup
Use the Get-StorageGroup cmdlet to retrieve a storage group object from the Active Directory directory service.


Enable-ExchangeCertificate
Use the Enable-ExchangeCertificate cmdlet to enable and disable an existing certificate that is in the local certificate store for different services.


Set-AvailabilityConfig
Use the Set-AvailabilityConfig cmdlet to set the access level for free/busy information.


Write-Warning
Writes a warning message.


Get-IPBlockListProvider
Use the Get-IPBlockListProvider cmdlet to view the configuration for a specific IP Block List provider on a computer that has the Hub Transport server role or Edge Transport server role installed.


Stop-Process
Stops one or more running processes.


Remove-ItemProperty
Deletes the property and its value from an item.


  
Latest Scripts from PoshCode.org

MoveExch2010SP1Archives
This script allows you to move the archive mailbox for a User or all your users to a database for Exchange 2010 SP1

Claimtypes, ADFS SP2010
Here's how you create a claim type mapping (for Claims based authentication) for Email and Role when using ADFS 2.0 and SharePoint 2010. Be sure to add both Email and Role when you create the trusted identity token issuer (if you add it afterwards, as an update, it wont work)

Get-Parameter 2.4
This is another *Must Have* upgrade, because I screwed up the last one ;-) * Added -ParameterName parameter to filter returned parameters * Added custom ToString() implementation to support -Like and -Match on the output * Enumerate the Parameters of a command by ParameterSet, *including DynamicParameters* * Now uses FormatData so the output is objects * Added calculation of shortest names to the aliases (borrowed from Shay Levy http://poshcode.org/1982)

MoveMailboxBySize
This script was developed to assist a customer with moving customizable batches of users, starting smallest mailboxes first in batches, and move them into datastores sorted by last name. This script is modular and can be extended to different filtering mechanisms, or a different datastore sorting criteria.

HttpRest 1.4
A few miscellaneous enhancements to HttpRest for pipelining urls, and the beginning of documentation ... *VERY OLD* documentation on "this post on HuddledMasses":http://huddledmasses.org/using-rest-apis-from-powershell-with-the-dream-sdk/ and I'm finally starting to update this to be an example of best practices ... I guess ;)

isMSDTC.ps1
Checks whether MSDTC is enabled for network access. By default MSDTC network access is disabled. This feature is needed by SQL Server Linked Servers

Get-ExchangeDBSizes
Gathers data from Exchange mailbox servers. These data include: Server\StorageGroup\Database (2007) or Database (2010), Total Size (in GB) of the disk, Size of the .edb file (in GB), Free disk space, Percent Disk Free, Total Mailboxes on the database, White Space, Total Free disk space, Total Percent Free disk space

Get-OnlineHelp
Retrieve Online Cmdlet Help I'm now using New-WebServiceProxy to take advantage of the well-formed XML provided by the "MSDN ContentService":http://services.msdn.microsoft.com/ContentServices/ContentService.asmx ...

Oliver Lipkau
Get-EmptyGroup: Function to find empty groups in Win2000/2003/2003R2/2008 domains.

Password Generator Form
Creates a form that allows you to generate a random password based on the requirements listed within the code. Can then print out the form to give to user. Password also saved to clipboard and can be pasted into the password reset dialog.
  
 

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
Jan 16

Written by: Karl Prosser
1/16/2010 8:27 PM

Have you ever just wanted to run a line or two of C# from within PowerShell and consume the resulting objects from PowerShell? Before V2 you had to do some codedom yourself Plus write a full dotnet class yourself. With V2 you can just do add-type but still you have to write a full class just to run an expression. Anyway how about a year ago after getting fed up with doing that, and also after seeing Mono's C# commandline interface i thought lets do something quick and dirty that could do this.. with the script that will follow you can do stuff like (c being an alias for the function that compiles and runs a C# expression

(c DateTime.Now).adddays(5)
(c "new{a=1,b=2,c=3}").b
c 'from x in Directory.GetFiles(@"f:\downloads") where x.Contains("win") select x'

an interesting thing i found out, was that with the C# compiler in memory i can't create more than one anonymous type (2nd example above) with the same signature (i.e int,int,int ) so the compiler will try to create the exact same type again. So it may seem pointless to call DateTime.Now when you can just do [DateTime]::Now but thats not the point, the point was it was running C#, returning an object that you could immediately use in powershell. I threw a linq example in there just to show you a glimpse of the potential. So how do you do this. You could even do this in V1 with codedom generation but here i'm using PowerShell V2

function run-csharpexpression([string] $expression )
{
$global:ccounter = [int]$ccounter + 1
$local:name  =  [system.guid]::NewGuid().tostring().replace('-','_').insert(0,"csharpexpr")
$local:ns = "ShellTools.DynamicCSharpExpression.N${ccounter}"

$local:template = @"
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace $ns
{
public static class Runner
{
public static object RunExpression()
{
return [[EXPRESSION]];
}
}
}
"@

$local:source = $local:template.replace("[[EXPRESSION]]",$expression)

add-Type $local:source -Language CsharpVersion3 | out-Null
invoke-Expression ('[' + $local:ns + '.Runner]::RunExpression()')
}

Thanks to Oising http://www.nivot.org for playing around with this when i was building it. So if i wanted to really turn this into something industrial quality what would i do?

  • try to work out a way that i could create the same anonymous type twice..
  • deal with exceptions well
  • make a version that you can pass in objects from powershell to the expression, and that they could even be put in as fields on the runner class so you could reference them by name from C#
  • Make a version that is designed to be run as part of the pipeline, where the function wrapper would manage the PROCESS block and call the csharp expression once every PROCESS block invocation.
  • I would possibly make a special version of Generics since generics interop is often one of the harder things in Dotnet
  • I'd have it keep a track of all the classes it has made, and have functions to look at them and interact with them and maybe reuse them. Particularly if they are parameterized.

Of course if you were so pathologically inclined you could very easily adapt this to make a VB.NET version too. Enjoy. And if anybody feels inspired to make a better more industrial quality version i'd love to have a look at it.

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