RunPowershellCommand From ASPx Page
private void RunPowershellCommand(string loginName)
{
try
{
PSSnapInException exc = new PSSnapInException();
RunspaceConfiguration rc = RunspaceConfiguration.Create();
PSSnapInInfo info = rc.AddPSSnapIn("Microsoft.Sharepoint.Powershell", out exc);
Runspace rs = RunspaceFactory.CreateRunspace(rc);
rs.Open();
Pipeline cmd = rs.CreatePipeline(string.Format("set-SPSite -Identity http://sitecollection -SecondaryOwnerAlias {0}",loginName));
Collection<PSObject> results = cmd.Invoke();
foreach (PSObject str in results)
SendToTextFile(str.ToString());
}
catch (Exception ex)
{
SendToTextFile("RunPowershellCommand() Error: " + ex.ToString());
}
}
Comments