0
我需要使用Powershell + Sharepoint Powershell擴展將新的託管元數據屬性添加到Sharepoint 2013中。如何通過Powershell更新Sharepoint 2013元數據託管屬性的「HasMultipleValues」
我是用C#做的。
爲了讓我做這一切的SharePoint託管屬性:
private static string GetAllSPManagedProperties(string searchApplication)
{
RunspaceConfiguration config = RunspaceConfiguration.Create();
PSSnapInException OExSnapIn = null;
PSSnapInInfo pssnap = config.AddPSSnapIn("Microsoft.SharePoint.PowerShell", out OExSnapIn);
//create powershell runspace
Runspace cmdlet = RunspaceFactory.CreateRunspace(config);
cmdlet.Open();
RunspaceInvoke scriptInvoker = new RunspaceInvoke(cmdlet);
// set powershell execution policy to unrestricted
scriptInvoker.Invoke("Set-ExecutionPolicy Unrestricted");
// create a pipeline and load it with command object
Pipeline pipeline = cmdlet.CreatePipeline();
Command cmd = new Command("Get-SPEnterpriseSearchMetadataManagedProperty");
pipeline.Commands.Add(cmd);
CommandParameter cmdParam = new CommandParameter("SearchApplication", searchApplication);
cmd.Parameters.Add(cmdParam);
//pipeline.Commands.Add("Out-String");
// this will format the output
IEnumerable<PSObject> output = pipeline.Invoke();
pipeline.Stop();
cmdlet.Close();
// process each object in the output and append to stringbuilder
StringBuilder results = new StringBuilder();
foreach (PSObject obj in output)
{
var typeNames = obj.TypeNames;
var p1 = obj.Properties["ID"].Value; // "AboutMe" object {string}
var p2 = obj.Properties["ManagedType"].Value; // Text object {Microsoft.Office.Server.Search.Administration.ManagedDataType}
var p3 = obj.Properties["PID"].Value; // 26 object {int}
var p4 = obj.Properties["Name"].Value; // "AboutMe" object {string}
var p5 = obj.Properties["HasMultipleValues"].Value; // true object {bool}
string managedTypeName = (string)p2.ToString();
results.AppendLine(obj.ToString());
}
return results.ToString();
}
的問題是,我試圖以編程方式設置選擇的託管元數據屬性的這個標誌「HasMultipleValues」。
obj.Properties["HasMultipleValues"].Value = true;
我不知道該怎麼做。我希望找到PSObject的一些更新方法(由pipeline.Invoke()返回,但不幸沒有發現任何有用的東西。
我的問題是,是否可以設置任何ManagedMetadataProperty的屬性以及如何?
調用commandlets fr om代碼並不漂亮。您應該查看管理API並使用適當的對象imo。 –