Exporting transport rule programmatically
Hi ,
I am trying to export transport rule programmatically.
My code works for simple commands like
get-exchangeserver, get-TransportRule etc
but if I try to give command importing rules to some file it gives error that the given command is not recognized as cmdlet, script….
My code is as below ( I have tried giving both windows authentication or user ‘s authentication who is exchange admin)
WSManConnectionInfo connectionInfo =
new WSManConnectionInfo(
serverUri,
SHELL_URI,
creds);
try
{
using (Runspace rs =
RunspaceFactory.CreateRunspace(connectionInfo))
{
PowerShell psh =
PowerShell.Create();
psh.Runspace = rs;
rs.Open();
psh.AddCommand("$file = Export-TransportRuleCollection -ExportLegacyRules" +"Set-Content
-Path " + @"C:\LegacyRules3.xml" +
"-Value file.FileData -Encoding Byte");
psh.Invoke();
I am using c# and exchange server 2010 PowerShell version is 1.0 the remoite os is winodws 7.
Any idea what correction I should do?
Regards,
Abhagwat