我需要使用 Powershell + Sharepoint Powershell Extensions 将新的托管元数据属性添加到 Sharepoint 2013 中。
我使用 C# 做到了这一点。
为了获得所有 Sharepoint Managed 属性,我做了这个:
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 的属性以及如何设置?