SharePoint 2016'da PowerShell kullanarak CSV Dosyasından Toplu Olarak Site Koleksiyonları Oluşturma


PowerShell cmdlet'i New-SPSite, SharePoint'te yeni site koleksiyonları oluşturmak için kullanılır. Diğer parametrelerle birlikte URL ve Sahip zorunlu parametrelerini alır. İşte bir örnek:

PowerShell Kullanarak SharePoint Site Koleksiyonu Oluşturma :

SharePoint'te bir site koleksiyonu oluşturmak için bu PowerShell betiğini kullanın:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Parameters to create new site collection
$SiteName = "Demo"
$SiteURL= "https://intranet.Crescent.com/sites/demo"
$SiteOwner = "Crescent\SPAdmin"
$SiteTemplate = "STS#0"
 
#create site collection with given parameters
New-SPSite -Url $URL -Name $SiteName -OwnerAlias $SiteOwner -Template $SiteTemplate

Bir CSV Dosyasından Toplu Olarak Birden Çok Site Koleksiyonu Oluşturmak için PowerShell:

Bir CSV dosyasından SharePoint site koleksiyonlarını toplu olarak oluşturmak için PowerShell'i kullanabilirsiniz. Bu blog yazısında, PowerShell kullanarak SharePoint'te bir CSV dosyasından birden çok site koleksiyonunun nasıl oluşturulacağını size göstereceğiz. Yeni bir proje veya girişim için hızlı bir şekilde birden fazla site koleksiyonu oluşturmanız gerekiyorsa bu yararlı olabilir.

Bir CSV dosyasından birden çok site koleksiyonu oluşturmak için bazı hata işleme ekleyelim ve New-SPSite'ı yeniden kullanılabilir bir PowerShell işlevine saralım.

  • 1. Adım: Aşağıdaki formatta bir CSV dosyası oluşturun. Sütun değerlerini gereksinimlerinize göre doldurun.

  • 2. Adım: CSV'den okumak ve toplu olarak site koleksiyonları oluşturmak için bu PowerShell betiğini kullanın.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Function to Create new Site Collection
Function Create-SPSite
{
  param
    (
        [string]$Name  = $(throw "Please Provide the Site Name!"),
        [string]$URL = $(throw "Please Provide the Site URL!"),
        [string]$Owner = $(throw "Please Provide the Site Owner!"),
        [string]$Template = $(throw "Please Provide the Site Template!")
    )
Try {
   #Set the Error Action
    $ErrorActionPreference = "Stop"
 
    #Check if the site collection exists already
    $SiteExists = Get-SPSite | where {$_.url -eq $URL}
    #Check if site exists in the recycle bin
    $SiteExistsInRecycleBin = Get-SPDeletedSite | where {$_.url -eq $URL}
  
    If($SiteExists -ne $null)
    {
        write-host "Site $($url) exists already!" -foregroundcolor red
    }
    elseIf($SiteExistsInRecycleBin -ne $null)
    {
        write-host "Site $($url) exists in the recycle bin!" -foregroundcolor red
    }
    else
    {
        #create site collection
        New-SPSite -Url $URL -Name $Name -OwnerAlias $Owner -Template $Template
        write-host "Site Collection $($url) Created Successfully!" -foregroundcolor Green
    }
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }
Finally {
    #Reset the Error Action to Default
    $ErrorActionPreference = "Continue"
 } 
}
 
#Read from CSV and create site collection
Import-Csv "C:\SitesToCreate.csv" | Foreach-Object { 
   Create-SPSite -Name $_.SiteName -URL $_.SiteURL -Owner $_.SiteOwner -Template $_.SiteTemplate  }

Bu komut dosyası, SharePoint'te birden çok site koleksiyonu oluşturmak için Import-Csv ve SharePoint cmdlet'inin birleşimini kullanır. Buna dahil edebileceğiniz İçerik Veritabanı, Dil, Site açıklaması vb. başka parametreler de vardır.

İlgili makaleler