我正在尝试使用Get-SPWebApplication,在此之前我尝试了这个
using (PowerShell ps = PowerShell.Create())
{
//ps.AddScript("Add-PSSnapin Microsoft.SharePoint.PowerShell");
string script = @"if ((Get-PSSnapin ""Microsoft.SharePoint.PowerShell"" -ErrorAction SilentlyContinue) -eq $null){ Add-PSSnapin ""Microsoft.SharePoint.PowerShell"" }";
ps.AddScript(script);
ps.AddCommand("Out-String");
Collection<PSObject> results = ps.Invoke();
if (ps.Streams.Error.Count > 0)
{
txtResult.Text = "Error:" + "\r\n";
foreach (var error in ps.Streams.Error.ToList())
{
txtResult.Text += (error.ToString()) + "\r\n";
}
}
}
并获取“没有为Windows PowerShell版本4注册管理单元”。错误。 但我能够从SharePoint 2013 Management Shell执行它们。
PS C:\Users\Administrator> Add-PSSnapin Microsoft.SharePoint.PowerShell
PS C:\Users\Administrator> Get-SPWebApplication
DisplayName Url
----------- ---
SharePoint - 80 http://win-3da6m0aggm9/
PS C:\Users\Administrator> Get-PSSnapin Microsoft.SharePoint.PowerShell
Name : Microsoft.SharePoint.PowerShell
PSVersion : 1.0
Description : Register all administration Cmdlets for Microsoft SharePoint Server
PS C:\Users\Administrator> Get-ExecutionPolicy
Unrestricted
我的环境:
如何使这项工作。我是否需要安装/注册任何其他组件? 谢谢您的帮助。