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

Popular posts from this blog

Windows Azure Package Build Error: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

Resource ID : 1. The request limit for the database is 180 and has been reached.

How to get Client's Location using IPAddress