powershell c#

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hello,

I tried to execute a simple Exchange 2007 Powershell command in my C# code:

Get-MailboxStatistics -Identity TestUser1

This Command works well in the Powershell command window.

According to the MSDN this should work like following:


--------------------------
RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();

PSSnapInException snapInException = null;

PSSnapInInfo info =
rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out
snapInException);

Runspace myRunSpace = RunspaceFactory.CreateRunspace(rsConfig);

myRunSpace.Open();

Pipeline pipeLine = myRunSpace.CreatePipeline();


RunspaceInvoke ri = new RunspaceInvoke(myRunSpace);

Collection<PSObject> commandResults =
ri.Invoke("Get-MailboxStatistics -Identity testuser1");

foreach (PSObject cmdlet in commandResults)

{

string cmdletName = cmdlet.Properties["DisplayName"].Value.ToString();

System.Diagnostics.Debug.Print(cmdletName);

}

------------------



But unfortunatly for some Users this command returns, that the mailbox could
not be found, even though the command works well in the Powershell window.
Where are differences in executing a command in the powershell window or in
code???

Alex


.



Relevant Pages

  • Re: Question Multi A/V Tool
    ... You have to execute NET START WORKSTATION in a Command Prompt. ... and in the Command Prompt window enter; ...
    (microsoft.public.security.virus)
  • Re: C Programming promt screen closes right away
    ... open a command prompt window, ... If you execute your program by double-clicking it's icon, ... done its thing, the command window closes, by design. ... Bringing you BeadWizard Design Software ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: VIM: :execute question - Help!
    ... > Using vim 6.3 under Linux, I'm trying to execute ... > the dict command in a new split window. ...
    (comp.editors)
  • Re: .bat to VBScript
    ... Use the vbscript to execute the batch file: ... policy to execute the script at logon. ... Param1 -- is the the path & command you want to execute. ... Param 2 - the style of the window the command is to be ran in. ...
    (microsoft.public.scripting.vbscript)
  • Re: how to access window network
    ... Now whenever you want to mount this file system issue the command ... The "user" attribue in the fstab entry will permit you to execute this ... > I would like to know how to access window network ...
    (Fedora)