1

I need to run exchange cmdlets from a c# console application.

I followed the guide from http://msdn.microsoft.com/en-us/library/bb332449.aspx for a simple command with a single parameter

The cmdlets I need to run is:

Get-MailboxStatistics -server evs | Select servername, StorageGroupName,databasename,@{expression={$_.TotalItemSize.value.ToKB()}},ItemCount,mailboxguid

I cannot specify the field that I need after the select command and I don't know how I can pass the expression @{expression={$_.TotalItemSize.value.ToKB()}} to cmdlets.

Is there a way to do it in managed code?

Dan McClain
  • 11,780
  • 9
  • 47
  • 67
user325823
  • 11
  • 1
  • Oooh,I so wish that you had gotten an answer to this question, other than the one to try Redemption. I'm working on the same thing, and if I get an answer I'll be back here. – ChrisW Aug 26 '10 at 23:10

3 Answers3

1

Have you tried the examples in the Exchange Management Shell SDK at http://msdn.microsoft.com/en-us/library/ff326155(v=EXCHG.140).aspx?

0

You can use Import-PSSession to move the remote session into a local powershell runspace.

Here are 2 methods.

Powershell to Exchange 2013 - Restricted language mode error http://blogs.msdn.com/b/akashb/archive/2010/03/26/how-to-call-ps1-script-from-managed-code-using-remote-powershell-exchange-2010.aspx

Community
  • 1
  • 1
Stuart
  • 671
  • 7
  • 20
0

Take a look at the Redemption library: http://www.dimastr.com/redemption/

I'm not sure if it satisfies your specific requirements but it does expose a lot of information through managed code.

David Neale
  • 16,498
  • 6
  • 59
  • 85