ค้นหาเว็บไซต์

SharePoint Online: นำเข้าข้อกำหนดไปยังชุดคำจาก CSV โดยใช้ PowerShell


ข้อกำหนด: นำเข้าข้อกำหนดไปยังชุดคำใน SharePoint Online จากไฟล์ CSV โดยใช้ PowerShell

จะนำเข้าข้อกำหนดไปยังชุดคำใน SharePoint Online ได้อย่างไร

ในโพสต์นี้ เราจะแสดงวิธีสร้างคำศัพท์จำนวนมากในชุดคำของ SharePoint Online ซึ่งอาจเป็นประโยชน์ถ้าคุณต้องการเพิ่มคำศัพท์จำนวนมากลงในชุดคำอย่างรวดเร็ว SharePoint นำเสนอวิธี OOTB ในการนำเข้าชุดคำจาก CSV แต่ไม่มีวิธีใดที่จะสร้างเพียงคำศัพท์ได้ ดังนั้น เราจะใช้ไฟล์ CSV ที่มีคำศัพท์มากมายเป็นอินพุตและ PowerShell เพื่อสร้างคำศัพท์ในชุดคำศัพท์

นี่คือไฟล์ CSV ของฉันที่มีรายการข้อกำหนดสำหรับชุดคำที่เรียกว่า "ตำแหน่งงาน" และเราสามารถใช้ PowerShell เพื่อสร้างข้อกำหนดจำนวนมากสำหรับชุดคำได้

ข้อกำหนดการนำเข้า SharePoint Online ในการตั้งค่าข้อกำหนดโดยใช้ PowerShell:

หากคุณต้องการเพิ่มคำศัพท์จำนวนมากให้กับชุดคำ PowerShell สามารถช่วยได้! โพสต์ในบล็อกนี้จะแสดงวิธีการนำเข้าคำศัพท์ไปยังชุดคำจาก CSV โดยใช้ PowerShell


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"
  
#Variables for Processing
$AdminURL = "https://crescent-admin.sharepoint.com"
$TermGroupName= "People"
$TermSetName="Job Title"
$CSVFile ="C:\Temp\ImportTerms.csv" 
$TermHeaderInCSV ="JobTitle"

Try {
    #Get Credentials to connect
    $Cred = Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminURL)
    $Ctx.Credentials = $Credentials

    #Get the term store
    $TaxonomySession=[Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Ctx) 
    $TaxonomySession.UpdateCache()
    $TermStore =$TaxonomySession.GetDefaultSiteCollectionTermStore()
    $Ctx.Load($TaxonomySession)
    $Ctx.Load($TermStore)
    $Ctx.ExecuteQuery()

    #Get Termstore data from CSV and iterate through each row
    Import-Csv $CSVFile | ForEach-Object {
      
        #Get the Term Group
        $TermGroup=$TermStore.Groups.GetByName($TermGroupName)

        #Get the term set
        $TermSet = $TermGroup.TermSets.GetByName($TermSetName)

        #CSV File Header Row in Term to Add
        $TermName = $_.$($TermHeaderInCSV)
 
        #Check if the given term exists already
        $Terms = $TermSet.Terms
        $Ctx.Load($Terms)
        $Ctx.ExecuteQuery()
        $Term = $Terms | Where-Object {$_.Name -eq $TermName}
    
        If(-not $Term)
        {
            #Create Term Set
            Write-host "Creating Term '$TermName'" -ForegroundColor Cyan
            $Term = $TermSet.CreateTerm($TermName,1033,[System.Guid]::NewGuid().toString())
            $Ctx.Load($Term)
            $Ctx.ExecuteQuery()
            $Term.TermStore.CommitAll()
            $TaxonomySession.UpdateCache()
            Write-host "New Term '$TermName' Added Successfully!" -ForegroundColor Green
        }
        else
        {
            Write-host "Term '$TermName' Exists Already!" -ForegroundColor Yellow
        }
    }
 }
Catch {
    write-host -f Red "Error Importing Term store Data!" $_.Exception.Message
} 

และผลลัพธ์:

หากคุณต้องการนำเข้ากลุ่มคำ ชุดคำ และข้อกำหนดจาก CSV ให้ใช้: SharePoint Online: วิธีเพิ่มข้อกำหนด ชุดคำ และกลุ่มคำจาก CSV โดยใช้ PowerShell

บทความที่เกี่ยวข้อง