SharePoint Online: PowerShell kullanarak Belge Kümesi Oluşturun


Gereksinim: PowerShell'i kullanarak SharePoint Online'da bir Belge Kümesi oluşturun.

SharePoint Online: PowerShell'i kullanarak Belge Kümesi Oluşturun

Diğer gönderimde SharePoint Online'da belge kümesinin nasıl oluşturulacağı açıklanırken: SharePoint Online'da Belge Kümesi Oluşturma - Adım Adım, bu blog yazısı size SharePoint Online'da belge kümesi oluşturmak için PowerShell'i nasıl kullanacağınızı gösterecek.

Kısaca belge seti, bir veya daha fazla ilgili belgeyi barındıran organizasyonel bir konteynerdir. Bu, masaüstünüzde farklı projeler için klasörler ve bu klasörlerin içinde bireysel görevler için alt klasörler oluşturmaya benzer. Bu komut dosyası, belge kümeleri özelliğinin etkin olduğunu, belge kümesi için içerik türünün zaten oluşturulduğunu ve kitaplığa eklendiğini varsayar. SharePoint Online'da belge kümeleri oluşturmak için PowerShell betiği aşağıda verilmiştir:


#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.DocumentManagement.dll"

#Parameters
$SiteURL="https://crescent.sharepoint.com/sites/marketing"
$DocumentLibraryName = "Proposal Documents"
$DocumentSetName = "Crescent Inc SharePoint"
#Content Type ID from the List!
$ContentTypeID="0x0120D52000683659260B26AF42AF65E57B09B613C2005AE31D539D0FB244BAEE6EA8CB1F4D52"

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

    #Get the Artifacts
    $DocumentLibrary=$Ctx.Web.Lists.GetByTitle($DocumentLibraryName)
    $Ctx.Load($DocumentLibrary)
    $Ctx.Load($DocumentLibrary.RootFolder)

    #Get content type from library by ID
    $ContentType = $DocumentLibrary.ContentTypes.GetById($ContentTypeID)
    $Ctx.Load($ContentType)
    $Ctx.ExecuteQuery()
 
    If($ContentType -ne $Null)
    {
        # sharepoint online powershell create document set from content type
        $DocumentSet = [Microsoft.SharePoint.Client.DocumentSet.DocumentSet]::Create($Ctx,$DocumentLibrary.RootFolder,$DocumentSetName,$ContentType.ID)
        $Ctx.ExecuteQuery()

        Write-host "Document Set '$DocumentSetName' Created Successfully!'" -f Green
    }
    else
    {
        Write-host "Content Type '$ContentTypeName' doesn't exist!'" -f Yellow
    }
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}

Bu komut dosyası, SharePoint Online'da yeni bir belge kümesi oluşturur.

SharePoint Online'da Belge Kümesi Oluşturmak için PnP PowerShell

PnP PowerShell kullanarak SharePoint Online'da belge kümesinin nasıl oluşturulacağı aşağıda açıklanmıştır:


#Parameters
$SiteURL= "https://Crescent.sharepoint.com/sites/Docs"
$ListName = "Documents"
$ContentTypeName = "Invoice Doc Set"
$DocumentSetName = "Crescent Invoices"

#Connect to the Site
Connect-PnPOnline -Url $SiteURL -Interactive

#Create a Content Type from "Document Set" Parent content type
$ParentCType = Get-PnPContentType -Identity "Document Set"
$ContentType = Add-PnPContentType -Name $ContentTypeName -Group "Crescent" -ParentContentType $ParentCType

#Add the Content Type to Library
Add-PnPContentTypeToList -List $ListName -ContentType $ContentType

#Add Document Set to Library
Add-PnPDocumentSet -List $ListName -ContentType $ContentTypeName -Name $DocumentSetName

Sonuç olarak, PowerShell kullanarak SharePoint Online'da Belge Kümesi oluşturmak, süreci otomatikleştirmenin ve manuel oluşturmayla karşılaştırıldığında zamandan tasarruf etmenin güçlü bir yoludur, özellikle de bunları çok sayıda hızlı bir şekilde sağlamanız gerektiğinde. CSOM yöntemlerini ve PnP PowerShell cmdlet'lerini kullanarak ve bu kılavuzda özetlenen adımları izleyerek, hızlı ve kolay bir şekilde Belge Kümeleri oluşturabilir ve bunları özel gereksinimlerinizi karşılayacak şekilde yapılandırabilirsiniz.

İlgili makaleler