I'm trying to set a TermSet.ID in Term Store, but fail since this is a read-only property. Is there any way to override the ReadOnly setting?

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"

$SiteCollection = Get-SPSite http://portal
$TaxSession = Get-SPTaxonomySession -Site $SiteCollection
$TermStore = $TaxSession.TermStores["Managed Metadata Service"] 

$TermStoreGroup = $TermStore.Groups["My Group"]
$TermSet = $TermStoreGroup.TermSets["My TermSet"] 

Write-Host "Term Store:" $TermStore.Id
Write-Host "Term Group:" $TermStoreGroup.Id
Write-Host "  Term Set:" $TermSet.Id

# Anoter GUID:

$TermSet.ID = "d60d07a0-0318-40c5-92e2-4bfdce2b401f";

And the output is as expected:

PS C:\Users\Administrator> C:\Company\Script\Set-TermSetID.ps1
Term Store: 0432716e-cf11-4447-bffa-62e376c444a5
Term Group: 9cda47a0-7783-4a37-b2ed-b498176e8480
  Term Set: 29b13163-7e2d-4d8e-87f7-81371ab87ee2
'ID' is a ReadOnly property.
At C:\Company\Script\Set-TermSetID.ps1:19 char:1
+ $TermSet.ID = "d60d07a0-0318-40c5-92e2-4bfdce2b401f";
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

How do I override the ReadOnly and set my own GUID? An alternative solution would be to set the GUID in an .csv import file, if that's possible?

Standard Import file (ImportTermSet.csv):

"Term Set Name","Term Set Description","LCID","Available for Tagging","Term Description","Level 1 Term","Level 2 Term","Level 3 Term","Level 4 Term","Level 5 Term","Level 6 Term","Level 7 Term"
"Political Geography","A sample term set, describing a simple political geography.",,True,"One of the seven main land masses (Europe, Asia, Africa, North America, South America, Australia, and Antarctica)","Continent",,,,,,
,,,True,"Entity defined by people, not visible to the naked eye","Continent","Political Entity",,,,,
,,,True,"Politically defined state with a geographic area governed by a central government","Continent","Political Entity","Country",,,,
,,,True,"Administrative division of a country","Continent","Political Entity","Country","Province or State",,,
,,,True,"Large sub-region usually containing many cities and towns","Continent","Political Entity","Country","Province or State","County or Region",,
,,,True,"Small village","Continent","Political Entity","Country","Province or State","County or Region","Hamlet",
,,,True,"Collection of homes and business, often incorporated","Continent","Political Entity","Country","Province or State","County or Region","Village",
,,,True,"A small city","Continent","Political Entity","Country","Province or State","County or Region","Town",
,,,True,"An incorporated town with a large population, usually governed by a mayor or council","Continent","Political Entity","Country","Province or State","County or Region","City",
,,,True,"A division of a city, often repesented in the city government","Continent","Political Entity","Country","Province or State","County or Region","City","District"
,,,True,"A sub-section of a city","Continent","Political Entity","Country","Province or State","County or Region","City","Borough"
,,,True,"Unofficial district or area of a city or town","Continent","Political Entity","Country","Province or State","County or Region","City","Neighborhood"

To create a new TermSet with a predefined GUID - use this script

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"

#Site Collection URL
$TaxonomySiteUrl = "http://portal"

#Access the termstore
$site = Get-SPSite $TaxonomySiteUrl  
$session = new-object Microsoft.SharePoint.Taxonomy.TaxonomySession($site)
$termstores = $session.TermStores | Select Name
$termstore = $session.TermStores[$termstores.Name]
$termgroup = $termstore.Groups | Where-Object {$_.Name -eq "MyTermGroup"}

$termgroup.CreateTermSet("MyTermSet", [System.Guid]("a31edf45-910e-4e02-a2f6-abd2ec0fdbd3"))

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.