Running A Powershell Command In C# Errors With "Cannot Invoke This Function Because The Current Host Does Not Implement It"

Nov 18, 2010

I have an application that I use to run Exchange Powershell commands inside C# code like below. This is an example of the relevant lines I use to run the powershell command.

RunspaceConfiguration rsConfig = RunspaceConfiguration.Create();
PSSnapInException snapInException = null;
//load Exchange shell
rsConfig.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out snapInException);
Runspace runSpace = RunspaceFactory.CreateRunspace(rsConfig);
//open runspace
runSpace.Open();
//setup pipeline
Pipeline pipeLine = runSpace.CreatePipeline();
String sScript = "get-mailbox -identity 'rj'";
//add script to pipeline
pipeLine.Commands.AddScript(sScript);
//run the script
pipeLine.Invoke();
pipeLine.Dispose();

This code works perfect in all cases until now. the script I am trying to run instead of the one above is to set the RetentionPolicy for a mailbox. The script I am trying to run looks like this: Set-Mailbox -Identity 'rj' -RetentionPolicy 'Main Campus Retention Policy' When I run this in powershell itself it works perfectly but when I try to run it using the code below I get the error, "Cannot invoke this function because the current host does not implement it."

From this error, it almost seems like the command that runs in C# cannot run the RetentionPolicy command but that doesn't make much sense. I have Googled this and tried everything suggested but no luck.

View 1 Replies


Similar Messages:

.net - Cannot Disable Or Enable An Exchange Mailbox Running A Powershell Command Inside C#?

Mar 14, 2011

I have a couple of powershell command that are very simple.

disable-mailbox dadelgad -confirm:$false
enable-mailbox -identity 'dadelgad' -database 'NET5014DB10' -Alias 'dadelgad'

The first command is to disable an exchange mailbox and the second enables the mailbox. I am logged in as a user who is in the Organization Management group which has full admin priviledges to Exchange but is not a domain admin. If I run these commands directly in Powershell, they work fine but they do not work when called from C#.

I created a very simple windows forms app that has a couple of buttons that invokes these commands from C# code. Running the app as the user with full Exchange right, most commands work with no problem such as get-mailbox -identity 'dadelgad'. I can set flags in Exchange, add alias emails and do most functions but I cannot disable or enable an account.Do I need to be a domain admin to do these functions. It almost seems like a permission issue but the user has full rights to Exchange and can perform both of these commands directly in Powershell.

View 1 Replies

Hosting Powershell In .net Mvc Running In Iis To Provide CLI For Custom Tasks?

Aug 22, 2010

I need CLI for our asp.net mvc application to perform maintenance tasks and some status tasks.

I think powershell is designed to provide CLI. But i do not know anything about it other than name.

How can i host powershell in asp.net mvc running in iis to provide CLI for custom tasks?

View 2 Replies

MVC :: HttpContext.Current.Request.Url.Host Not Correct When Using Host Headers In IIS 7.5

Feb 24, 2011

I have one IIS entry with AppPool integrated mode. There are 5 or more host headers assigned. The application pulls data based on the host name from Request.Url.Host. When I have 2 or more sites open at the same time the value of the Request.Url.Host is the same across all the sites. About every 30 seconds it resets itself to the correct value from the last request and shows that value on the other sites. So ultimately the sites are loading the same data. The value in the HOST server variable is incorrect as well.

View 1 Replies

Web Forms :: Saving PDF Files By Suppressing Save Dialog Box When Running Print Command Through Command Line

Sep 2, 2010

[Code]....

Using above code, I got succeeded in printing PDF file through command line. But it runs the Acrobat Reader and opens Save dialog box.

In my case, I want to suppress Save dialog box and save the file on other location using c# coding. I mean I want to save a PDF file behind the scene.

View 1 Replies

How To Invoke Server Side Function Before Invoking Client Side Function

Oct 7, 2010

I am using an update panel in my application. Inside the update panel i am trying to trigger a html button, which in turn should invoke a server side function after which i need to invoke a client side function.But the client side function is getting invoked first where as the server side function is not getting invoked at all.

Here is my code

<asp:UpdatePanel ID="embedcodepanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnembedurl" EventName="onclick"/>
</Triggers>
<ContentTemplate>
<label id="lbl_embedcode" class="hide">Site Embed Code:</label>
<textarea id="embedCode" class="embedCode hide"> CreateEmbedURL('<%=_redirectUrl%>')

View 1 Replies

Web Forms :: Invoke JavaScript Function From ActiveX Control

Mar 4, 2010

I have to fullfill a requirement where my activeX control (developed in c#) need to invoke a callback JavaScript function asynchronously (or) synchronously (or) in both ways. I can handle the context using threads. JavaScript:

function handler_1(){ ..... }
myActiveXObject.registerCallBack(handler_1);

Where in ActiveX control, I need a function "registerCallBack" to accept the argument. But I have no clue how to invoke that registered JavaScript function from my ActiveX control. By digging MSDN forum, I found something as script.GetType().InvokeMember("myJSFunctionName", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public, null, script, null);

the above line throwing me an exception Unknown Name etc. I do have the definition for "myJSFunctionName" in javascript and I got the script object from the document object.

View 2 Replies

Web Forms :: Invoke C# Function From Another Project Without Adding Reference?

Sep 24, 2010

There is a C#.net libraray project whose dll name is customer.dll. It has a class name customer with a function name show(). I want to call this function from another project but dont want to add reference to the caller project. Can this be done? Is there any C#.net class that can acheive this?

View 1 Replies

Catch Command Prompt Errors In Code?

Sep 6, 2010

I am running ffmpeg.exe from command prompt through asp.net code. Is there any method to know success and errors of the ffmpeg.exe execution in asp.net code ?

My code is as follows:

string OutputFile, FilArgs;
//output file format in swf
//outputfile = SavePath + "SWF\" + withoutext + ".swf";
OutputFile = SavePath + "SWF\" + WithOutExt + ".flv";
//file orguments for FFMEPG
//filargs = "-i "" + inputfile + "" -ar 22050 "" + outputfile;
FilArgs = "-i "" + InputFile + "" -ar 22050 "" + OutputFile;
//string spath;
//spath = Server.MapPath(".");
Process proc;
proc = new Process();
proc.StartInfo.FileName = spath + "\ffmpeg\ffmpeg.exe";
proc.StartInfo.Arguments = FilArgs;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.RedirectStandardOutput = false;
try
{
proc.Start();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
proc.WaitForExit();
proc.Close();

View 2 Replies

MVC :: Running On Shared-Host Providers?

Jul 25, 2010

i want to run an ASP.NET MVC 2 web application on a .NET 3.5 shared-host provider, I will not mention this provider's name. I will refer to this provider as FOO.

The general community that uses FOO states that it can be done, but the Tech Support at FOO are not consistent:

"What is MVC?" or "Yes, but only on dedicated hosts", or "Yes, it can upon both dedicated and shared hosts" -but they do not know the details.

The general community states that FOO can host ASP.NET MVC 2 on shared hosts, but details on how it is done is inconsistent.

What are general rules of thumb about setting up an ASP.NET MVC 2 for a shared-host environment?

Let us say that we create a vanilla (default) MVC 2 web application from withinVS 2008/2010. What modification should I perform, other than use .NET 3.5 andcopy local System.Web.Mvc.

View 6 Replies

Configuration :: Running ASPNET_REGSQL.EXE On A Shared Host

Jun 28, 2010

I want to be able to run aspnet_regsql.exe to create the membership tables on a shared host. But since, it is a shared host, I can't do that. I however can create the tables on my box. How do I copy them over?

View 4 Replies

Errors Running .NET 1.1 On IIS7 (applicationHost.config)?

Jan 11, 2011

I am trying to port an existing ASP.Net 1.1 website to another web server that currently runs IIS7 and a number of websites that target either .Net 2.0, 3.5 or 4.0. All other sites continue to work perfectly. Unfortunately, I can only browse static files on the newly imported site. If I try to access any of the Features in IIS7 for the new sit

View 1 Replies

Host Websites In Iis 7 (currently Running On Windows 7 Release Candidate)?

Mar 4, 2010

I have created three basic websites using VS2010 and they are working fine when invidually run from visual studio. But in order to get the full functionality of the websites, they have to be run simultaneously. There are iframes inside one contaning pages from other website.

What is the way it can be done? Is hosting the only solution to it? If so please tell me how to host them in IIS7( i am currently running on windows 7 release candidate)

View 2 Replies

MVC :: Implement In This Function Public Function FetchData (ByVal DropdownValue As String)?

Jan 5, 2010

i followed this link [URL] and i get selected value from dropdownlist using jquery

i created 3 partial views .

i need depend's on dropdownvalue redirect to partial page , so how can i implement in jquery with conditions?? or how can i implement in this function Public Function FetchData(ByVal dropdownValue As String) As ActionResult??

View 1 Replies

ADO.NET :: Sql Command Running Into Exception?

Sep 7, 2010

SqlCommand MyCommand1 = new SqlCommand("Insert into incoming_inventory(division_code,inv_date) select '"+dd_district.SelectedValue+"','+'" + DropDownList3.SelectedValue + "'+'/'+dayno+'/'+'2010' from month_day where month_name=datename(month,dateadd(month," + DropDownList3.SelectedValue +",0)-1)'", MyConnection1);

View 2 Replies

Where Is Origin Of HttpContext.Current.Request.Url.Host

Apr 28, 2010

Why does HttpContext.Current.Request.Url.Host return a different URL than the URL used in the Web browser? For example, when entering "www.someurl.com" in the browser, the HttpContext.Current.Request.Url.Host variable is equal to "www.someotherurl.com".

View 1 Replies

Get The Host Domain Name Without Using HttpContext.Current.Request?

Feb 1, 2010

I've got an ASP .Net application running on IIS7. I'm using the current url that the site is running under to set some static properties on a class in my application. To do this, I'm getting the domain name using this (insde the class's static constructor):

var host = HttpContext.Current.Request.Url.Host;

And it works fine on my dev machine (windows XP / Cassini). However, when I deploy to IIS7, I get an exception: "Request is not available in this context".

I'm guessing this is because I'm using this code in the static constructor of an object, which is getting executed in IIS before any requests come in; and Cassini doesn't trigger the static constructor until a request happens. Now, I didn't originally like the idea of pulling the domain name from the Request for this very reason, but it was the only place I found it =)

So, does anyone know of another place that I can get the host domain name? I'm assuming that ASP .Net has got to be aware of it at some level independent of HttpRequests, I just don't know how to access it.

View 3 Replies

Databases :: Uploading Excel Sheet When My Application Running On Local Host

Feb 8, 2011

there is broblum for uploading excel sheet when my application runing on local host but there is no problum on vs enviroment . i am using the following connection string code

strConn =
"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + path +
";Extended Properties=Excel 8.0;"
;

View 3 Replies

C# - Running A Command Line In A Web Form?

Feb 10, 2011

i would like to do an automated test system which will allow me to run a batch file automatically. right now the procedure is:

[code]...

i would like to have a button so that once the user clicks it, the above processes are ran automatically.i have something done, which allows me to open up cmd.exe as shown below:protected void Button1_Click(object sender, EventArgs.

View 2 Replies

MVC :: ASCX Control - Return The Current Host View Name?

May 27, 2010

I am just wondering whether it is possible to return the name of the view an ascx control is currently being rendered in? Is there an object I can use to access the name?

Basically I want the control to dynamically set certain text within itself dependant on the view it is rendered within.

View 2 Replies

Web Forms ::Running Command Line From An ASP.NET Page?

Feb 22, 2010

This works:

[Code]....

If I open a command line on that server and type that command, it returns all of the scheduled tasks for the system. If I run that code, it returns a blank page.

View 14 Replies

SQL Server :: Command Does Not Exist In The Current Context?

Jul 26, 2010

using System.Data.SqlClient;
using System.Data;
public static SqlDataReader GetCategories()
{
SqlDataReader reader;
string sql = "SELECT * FROM CATEGORIES";
using (SqlCommand command = new SqlCommand(sql, ConnectionManager.GetConnection())); //possible //mistaken empty statement
{
reader = command.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.CloseConnection);
}
}

I am getting a couple of errors in this code that I can't figure out. One is regarding the empty statment next to the comments above and the other one is regarding reader=command, it says command does not exist in the current context.

View 2 Replies

Security :: Folder Permission Running Locally / Attrib Command Is Not Working

Jun 28, 2010

I have a very simple and stupid problem but I'm unable to find a solution. I'm trying to create folders and files locally through my code, however I get a permission exception when I try to write in a folder in my application. Normally I'd run this on a remote server, and ask the system administrator for writing permission on this specific folder, but I need to run this locally for the moment.

If I navigate to the file in windows explorer, and right click the folder and click on Properties, I can see that it's set as Read Only. However when I try to disable this tickbox and click on Accept, nothing happens. It ignores me, and next time I open the Properties of this same folder, it's still marked as Read Only.

I've googled this and found a solution which implies using MS-DOS and a command named "attrib". This is not working for me either. I also read about adding an ASP.NET account on my PC and granting the right permissions to this, but I'm not sure how to do is.

View 8 Replies

Web Forms :: Create Website With Multiple Host Address Using Iisweb/ Create Command Line

Jan 21, 2010

I am creating a web site through command line. I am able to create a web site with single host address. But i want multiple host address for a website. this is the command I am using iisweb /create D:Test Test.com /d [URL]

View 6 Replies

Forms Data Controls :: How To Get The Current Row In GridView Row Command Event

Apr 28, 2010

i use a wizard in my page the first step contains a Gridview.

[Code]....

It runs very well until i use the Gridview paging. In this case i get following error-message."Unable to cast object of type 'System.Web.UI.WebControls.Wizard' to type 'System.Web.UI.WebControls.GridViewRow'." If i use this code to get the gridview-rowDim row As GridViewRow = _ grid.Rows(Convert.ToInt32(e.CommandArgument)) paging runs, but i cannot use the commandDropdown.This is my control. I use commanddorpdown [Code]....

I have downloaded the Control form this page.
[URL]19606_On_ASP_NET_Forums_How_to_develop_a_command_capable_DropDownList.aspxHas anybody an idea to solve my problem?

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved