Hi I have the following bit of code
//set up exchange server name
var Exchangesrv = "ex1.iah.ac.uk";
// Initialize PowerShell engine
var shell = PowerShell.Create();
// Add the script to the PowerShell object
shell.Commands.AddScript("Invoke-Command -Computername hostname.example.com -ScriptBlock{get-alias}");
// Execute the script
var results = shell.Invoke();
Input.DataSource = results;
Input.DataBind();
So very simply I want to invoke a power shell command and the "input" is a list box object I am populating
But When i run it on the IIS server it does not work, I think it is because the IIS application is not running with an account that is admin on the remote server I am trying to run the command against. Can any one help resolving this. How can I get the webpage to call this invoke command with the right credentials?
Edit
So i decided to create a profile on the web server that means when the account that I am using opens power-shell the exchange module is loaded. But I don't see this loading when using the following code
using (var powershell = PowerShell.Create())
{
//powershell.Runspace = runspace;
// Add the script to the PowerShell object
//powershell.AddScript("Get-alias");
powershell.AddScript("Get-DynamicDistributionGroup");
// Execute the script
var results = powershell.Invoke();
Input.DataSource = results;
Input.DataBind();
So What should be happening is power shell runs locally on the web server, but i need it to load the profile however I cant see why it is not doing it. Is there a command to force it to load the moduel.
Invoke-Commandhas a-Credentialparameter that could also be used for for impersonation.Log4Net, to ensure that you can accurately diagnose this and future problems. IIS logging is designed to tell you about the HTTP call, not the application processing.