$envTermGroup="Document Management Tags"$termSId="b6ddada5-25b5-xxx-xxxx-b473235d6278"#c65620d8-ee35-4a47-83ed-3da15bf74a0a" #Tags old term set $csvPath="C:\Users\343614\OneDrive - ssss\Documents\scripts\termsets_import\Import csv - all tags - with synonyms - Delta - test.csv"$logFile=".\term_synonyms_Log-$(Get-Date-Format"yyyyMMdd-HHmm").csv"functionLog-Message{param([string]$Message,[string]$Status)switch($Status){"Success"{$color="Green"}"Info"{$color="Blue"}"Error"{$color="Red"}default{$color="White"}}Write-Host-ForegroundColor$color"$Status => $Message"$logEntry=[PSCustomObject]@{Timestamp=(Get-Date).ToString("yyyy-MM-dd HH:mm:ss")Message=$MessageStatus=$Status}$logEntry|Export-Csv-Path$logFile-Append-NoTypeInformation}$clientId="xxxx"Connect-PnPOnline-Urlhttps://contoso.sharepoint.com/-clientid$clientIdLog-Message-Message"Connected to SharePoint"-Status"Info"$invocation=(Get-VariableMyInvocation).Value$directorypath=Split-Path$invocation.MyCommand.PathFunctionAdd-Synonyms($ImportCsv,$termsetId,$termGroup){Import-Csv$ImportCsv|ForEach-Object{$labels=$($_.Synonyms)if($labels){$i=7$termName=""while(($termName-eq""-or$termName-eq$null)-and$i-ge1){$termName=$($_.$("Level "+$i.ToString()+" Term"))$i--;}if($termName){try{if($i-eq0){$term=Get-PnPTerm-Identity$termName-TermSet$termsetId-TermGroup$termGroup}else{$term=Get-PnPTerm-Identity$termName-TermSet$termsetId-TermGroup$termGroup-Recursive}Log-Message-Message"Processing $termName"-Status"Info"}catch{Log-Message-Message"$termName not found"-Status"Error"}if(!$term){Log-Message-Message"$termName not found"-Status"Error"}if($term){foreach($lin$labels.split(',')){$l=$l.trim()if($l){try{$otherLabels=Get-PnPTermLabel-Lcid1033-Term$term$otherLabel=""foreach($labelin$otherLabels){if($label.Value-eq$l){$otherLabel=$label.Value.trim()}}if(!$otherLabel){$term.CreateLabel($l,1033,$false)Start-Sleep-Seconds5Log-Message-Message"Adding label $l to term $termName"-Status"Success"}}catch{Log-Message-Message"$($_.Exception) adding $l"-Status"Error"}}}}}}}}# Create Term Grouptry{$termGroup=Get-PnPTermGroup-Identity$envTermGroup-ErrorActionSilentlyContinueif(!$termGroup){New-PnPTermGroup-GroupName$envTermGroupLog-Message-Message"Created Term Group $envTermGroup"-Status"Success"}}Catch{Log-Message-Message"Term Group already exists"-Status"Info"}# Import Term Set#Import-PnPTermSet -GroupName $envTermGroup -TermSetId $termSId -Path $csvPath -SynchronizeDeletionsStart-Sleep-Seconds5Add-Synonyms$csvPath$termSId$envTermGroup