/ / C # Zdalny Powershell SharePoint 2010 - c #, sharepoint, powershell, sharepoint-2010, powershell-v2.0

C # Zdalny Powershell SharePoint 2010 - c #, sharepoint, powershell, sharepoint-2010, powershell-v2.0

Próbuję uruchomić polecenia powershell na zdalnym serwerze SharePoint z aplikacji konsoli c # To jest kod, który mam do tej pory.Będzie działać bez błędów, ale nic nie robi. Co robię źle?

Dzięki

nazwa serwera, hasło użytkownika i adres URL zostały usunięte

    public static string RunScript()
{

Runspace remoteRunspace = null;
openRunspace("http://server/wsman",
"http://schemas.microsoft.com/powershell/Microsoft.PowerShell",
@"domainuser",
"password",
ref remoteRunspace);
try
{
StringBuilder stringBuilder = new StringBuilder();
using (PowerShell powershell = PowerShell.Create())
{

powershell.Runspace = remoteRunspace;
powershell.AddScript("Add-PsSnapin Microsoft.SharePoint.PowerShell");
powershell.AddScript("enable-SPFeature -identity "2dfc204b-e9da-4c6c-8b4f-c2f7c593ad4e" -url sharepointsite -Confirm:$False");
powershell.Invoke();
Collection<PSObject> results = powershell.Invoke();
remoteRunspace.Close();
foreach (PSObject obj in results)
{
stringBuilder.AppendLine(obj.ToString());
}
}

return stringBuilder.ToString();
}
catch (Exception e)
{

return "";

}


}

public static void  openRunspace(string uri, string schema, string username, string livePass, ref Runspace remoteRunspace)
{
System.Security.SecureString password = new System.Security.SecureString();
foreach (char c in livePass.ToCharArray())
{
password.AppendChar(c);
}
PSCredential psc = new PSCredential(username, password);
WSManConnectionInfo rri = new WSManConnectionInfo(new Uri(uri), schema, psc);
rri.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
rri.ProxyAuthentication = AuthenticationMechanism.Negotiate;
remoteRunspace = RunspaceFactory.CreateRunspace(rri);
remoteRunspace.Open();
}

Odpowiedzi:

1 dla odpowiedzi № 1

Możesz spróbować sprawdzić, czy masz dostęp doBazy danych SharePoint, aby poprawnie dodać snap-in, potrzebujesz uprawnienia ShellAccess w bazie danych konfiguracji, jak pamiętam i uprawnienia administratora farmy. Być może twój skrypt nie może dodać snap-in, więc nie może zrobić nic z modelem obiektu SharePoint.