Get managed metadata using Powershell
-
23-01-2021 - |
Pregunta
I want to copy the single managed metadata Field [Base currency] Value.
$newItem["Base Currency"] = $item["Base currency"] it's wrong because it's a managed metadata.. we don't get the value of managed metadata as a single line of text
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq
'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) { Add-PSSnapin Microsoft.SharePoint.Powershell }
$web = Get-SPWeb http://intranet/
$listProspect = $web.Lists["Prospects"]
$Fund = Get-SPWeb http://intranet/cccc
$listFunds = $Fund.Lists["New Fund"]
foreach($item in $listProspect.Items | Where {$_["Approved"] -eq
"string;#Approved"})
#Approved is a calculated Column so it's input have the value string;#..
{
$newItem = $listFunds.Items.Add();
$newItem["Title"] = $item["Client's Name"]
**$newItem["Base Currency"] = $item["Base currency"]**
$newItem.Update()
}
Solución
This is the solution :
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq
'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) { Add-PSSnapin Microsoft.SharePoint.Powershell }
$web = Get-SPWeb http://intranet/
$listProspect = $web.Lists["Prospects"]
$Fund = Get-SPWeb http://intranet/cccc
$listFunds = $Fund.Lists["New Fund"]
foreach($item in $listProspect.Items | Where {$_["Approved"] -eq
"string;#Approved"})
#Approved is a calculated Column so it's input have the value string;#..
{
$newItem = $listFunds.Items.Add();
$newItem["Title"] = $item["Client's Name"]
$CurrencyFieldValue = $item["Base currency"] -as
[Microsoft.SharePoint.Taxonomy.TaxonomyFieldValue];
$CurrencyFieldValue.TermGuid;
$newItem["Base Currency"] = $CurrencyFieldValue.TermGuid;
$newItem.Update()
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a sharepoint.stackexchange