Dear All,
we are trying to automate the user account management using Powershell to handle all interactions with Exchange 2007.
The powershell commands are launched from a webservice developed in ASP.NET (C#).
The project is practically over aside from the export of the mailbox.
When I try to execute the following command:
export-mailbox -identity "Mister x" -baditemlimit 1147483648 -pstfolderpath "d:\path\MisterX.pst"
We get an error:
Export-Mailbox error results: Error was found for MisterX (MisterX@MisteryComp.net) because: An unknown error has occurred., error code: -2147219963
The same command runs fine from the exchange powershell console (same user, same server)
We also noticed the command completes successfully if I first run the exact same command directly on powershell (from the same server) and then leave the console window open.
If I close the console, the application starts failing again with the same error.
If I run the application pool that owns the webservice with Domain Admin account, everything works fine but the user I would like to use has all the necessary rights.
I get the feeling Powershell in order to function properly needs a session open in a specific way that I do not understand.
Here following the relevant portion of code:
RunspaceConfiguration runspaceConf = RunspaceConfiguration.Create();
PSSnapInException PSException = null;
PSSnapInInfo info = runspaceConf.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out PSException);
Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConf);
runspace.Open();
System.Management.Automation.SwitchParameter spConfirmYes;
int iNbmaxerreurs = 1147483648;
spConfirmYes = false; //Always False
Pipeline pipelineEM = runspace.CreatePipeline();
pipelineEM.Commands.Add("Export-Mailbox");
pipelineEM.Commands[0].Parameters.Add("Identity", MailID.ToString());
pipelineEM.Commands[0].Parameters.Add("BadItemLimit", iNbmaxerreurs);
pipelineEM.Commands[0].Parameters.Add("Confirm", spConfirmYes);
pipelineEM.Commands[0].Parameters.Add("PSTFolderPath", sExportfilePath.ToString() + ExportfileName.ToString() + ".pst");
// Result Recuperation:
System.Collections.ObjectModel.Collection
psobjResults;
System.Collections.ObjectModel.Collection