U
Uddipto Banerji
Guest
I'm using Visual Studio 2015 Enterprise Edition and target framework is 4.5. I'm calling a MVC controller. I have a powershell script which resides in the same server. The dlls I'm using are
1. System.Management.Automation v4.0
2. WindowsBase V4.0
In the app pool I'm using the local admin and my application is running under the same app pool. I have checked the group policy and updated accordingly.
When I'm trying to invoke Powershell using Runspace.open() I'm receiving the error.
Connecting to remote server localhost failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
public static string Input(string Server, string Volume, string size, string region, string username, string password)
{
FileStream fileStream;
log.Info("\n");
log.Info("Input- Method called:");
string _consoleOutput = string.Empty, _output = string.Empty;
string _outputfilePath = @"c:\diskextension\Output";
string _powerShellScript = @"C:\diskextension\diskexterror_dev.ps1";
try
{
// TODO: Add delete logic here
string userID = "dir\\" + username.ToString();
string userpassword = password.ToString();
log.Info("username " + userID);
StringBuilder stringBuilder = new StringBuilder();
var con = new WSManConnectionInfo();
log.Info("Pushing username in PSCredential- " + userID.ToString().Trim());
con.Credential = new PSCredential(userID.ToString().Trim(), userpassword.ToString().Trim().ToSecureString());
Runspace runspace = RunspaceFactory.CreateRunspace(con);
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript("Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted");
string _str = @"-Server " + Server + " -Volumeletter " + Volume + ": -deltasize " + size + " -Logfile " + _outputfilePath + " -region " + region + " -username " + userID + " -password " + DataEncrypterDecrypter.Decrypt(password, "sblp-3hn8-sqoy19").ToString().Trim();
pipeline.Commands.AddScript(_powerShellScript + _str.ToString());
pipeline.Commands.Add("Out-String");
var results = pipeline.Invoke();
runspace.Close();
foreach (PSObject obj in results)
{
stringBuilder.AppendLine(obj.ToString());
stringBuilder.Append("\n");
}
}
catch (Exception ex)
{
throw ex.ToString();
}
return stringBuilder.ToString().Trim();
}
Can someone let me know any noticeable errors for which I'm receiving this error.
Continue reading...
1. System.Management.Automation v4.0
2. WindowsBase V4.0
In the app pool I'm using the local admin and my application is running under the same app pool. I have checked the group policy and updated accordingly.
When I'm trying to invoke Powershell using Runspace.open() I'm receiving the error.
Connecting to remote server localhost failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
public static string Input(string Server, string Volume, string size, string region, string username, string password)
{
FileStream fileStream;
log.Info("\n");
log.Info("Input- Method called:");
string _consoleOutput = string.Empty, _output = string.Empty;
string _outputfilePath = @"c:\diskextension\Output";
string _powerShellScript = @"C:\diskextension\diskexterror_dev.ps1";
try
{
// TODO: Add delete logic here
string userID = "dir\\" + username.ToString();
string userpassword = password.ToString();
log.Info("username " + userID);
StringBuilder stringBuilder = new StringBuilder();
var con = new WSManConnectionInfo();
log.Info("Pushing username in PSCredential- " + userID.ToString().Trim());
con.Credential = new PSCredential(userID.ToString().Trim(), userpassword.ToString().Trim().ToSecureString());
Runspace runspace = RunspaceFactory.CreateRunspace(con);
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript("Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted");
string _str = @"-Server " + Server + " -Volumeletter " + Volume + ": -deltasize " + size + " -Logfile " + _outputfilePath + " -region " + region + " -username " + userID + " -password " + DataEncrypterDecrypter.Decrypt(password, "sblp-3hn8-sqoy19").ToString().Trim();
pipeline.Commands.AddScript(_powerShellScript + _str.ToString());
pipeline.Commands.Add("Out-String");
var results = pipeline.Invoke();
runspace.Close();
foreach (PSObject obj in results)
{
stringBuilder.AppendLine(obj.ToString());
stringBuilder.Append("\n");
}
}
catch (Exception ex)
{
throw ex.ToString();
}
return stringBuilder.ToString().Trim();
}
Can someone let me know any noticeable errors for which I'm receiving this error.
Continue reading...